π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘
We analyzed the comments on this post to provide some guidance: #14920 (comment).
π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘π‘
What is thisThis is a new ESLint rule that verifies the list of dependencies for Hooks like useEffect
and similar, protecting against the stale closure pitfalls. For most cases it has an autofix. We'll add more documentation over the next weeks.
yarn add eslint-plugin-react-hooks@next
# or
npm install eslint-plugin-react-hooks@next
ESLint config:
{ "plugins": ["react-hooks"], // ... "rules": { "react-hooks/rules-of-hooks": 'error', "react-hooks/exhaustive-deps": 'warn' // <--- THIS IS THE NEW RULE } }
Simple test case to verify the rule works:
function Foo(props) { useEffect(() => { console.log(props.name); }, []); // <-- should error and offer autofix to [props.name] }The lint rule complains but my code is fine!
If this new react-hooks/exhaustive-deps
lint rule fires for you but you think your code is correct, please post in this issue.
Please include these three things:
It might be simple to you β but itβs not at all simple to us. If your comment doesn't include either of them (e.g. no CodeSandbox link), we will hide your comment because itβs very hard to track the discussion otherwise. Thank you for respecting everyoneβs time by including them.
The end goal of this thread is to find common scenarios and transform them into better docs and warnings. This can only happen when enough details are available. Drive-by comments with incomplete code snippets significantly drive down the quality of the discussion β to the point that it's not worth it.
petercr, dpyzo0o, zjaml, razh, sadamia and 34 morepetercr, dpyzo0o, kevin940726, saaage, Jessidhia and 7 morepetercr, alexkrolick, ahtee, dpyzo0o, eps1lon and 23 moreahtee, deadcoder0904, markozxuu and plotnikovn
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4