gaearon / gaearon/react-hot-loader

Hooks unnecessarily update

Open
#1,365 6 comments 4 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
12.2k
Forks
775
PR merge metrics
No merged PRs in 30d

Description

Whenever I make changes to a component that doesn't even involve hooks, all hooks with dependencies in them get updated undesirably. E.g.:

```js
const dispatch = useDispatch();
useEffect(() => {
dispatch(loadPosts());
}, [dispatch]);
```

So any tiny text change I make anywhere, this `useEffect()` callback gets called, causing my spinner to show, and load my posts again unnecessarily.

If I removed `dispatch` from the hook dependencies, then the `useEffect()` does not get called, just what I want. But I violate the react-hooks/exhaustive-deps eslint rule that way.

Also, if I add any static value to the dependencies, then also, it always gets updated, which is not what I want. Note that each time I don't edit the hook itself, and in fact not even the same file as the hook.

Is this normal?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.