How to disable the rule react-hooks/exhaustive-deps?
See original GitHub issueI’m trying to disable the rule react-hooks/exhaustive-deps
. I’ve tried adding "react-hooks/exhaustive-deps": "off",
to .eslintrc without any luck.
How do I disable this rule? Thanks!
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:68 (15 by maintainers)
Top Results From Across the Web
reactjs - How do I configure eslint rules to ignore react-hooks ...
Usually you don't want to disable the rule. However, there are few cases where it's worthwhile to disable it. For example, if you're...
Read more >You probably shouldn't ignore react-hooks/exhaustive-deps ...
We have a seemingly-easy out: we can ignore the linting error by placing a // eslint-disable-next-line right above the dependency array. Here's ...
Read more >Rules of Hooks - React
By following this rule, you ensure that Hooks are called in the same order each time a component renders.
Read more >Understanding the React exhaustive-deps linting warning
What is the exhaustive deps lint rule? · count to the dependency array or removing the dependency array altogether. If you remove the...
Read more >How bad is disabling `react-hooks/exhaustive-deps`? - Reddit
How bad is disabling `react-hooks/exhaustive-deps`? ... Hello! I learning react and I try to create some useEffects (useInit - run once, useHttp - ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For us, one of the primary places we’re receiving this warning is for
useEffect
hooks that we only want to run when the component mounts, and never again for that component.As a concrete example, the app we’re working on can display a small notification in the top right corner that automatically disappears after 15 seconds. Here’s a super trimmed down version of what that might look like:
This complains because
hideSelf
is not a dependency listed in theuseEffect
hook. But that’s intentional; we only want that hook to run when this component mounts.Is there a better way to design this? Or would this be a false positive?
This is one of the reasons I don’t want to add “unnecessary” things to my deps, as it makes the code look more complex and confusing. I totally agree that empty brackets tell you that it’s CDM. There are many cases in my app where I just want to fetch once when the component mounts, but now I need to choose whether I want to add bunch of
// eslint-disable-next-line react-hooks/exhaustive-deps
lines or add the props as deps, but then I need to make sure the effect doesn’t run any code when one of the deps changes. @gaearon I believe this is the main problem with this rule or hook. Perhaps we just need more hooks or options?