Bug: eslint exhaustive-deps doesn't recognize JSXIdentifier as used
See original GitHub issuefunction Component({reportType}) {
let Report = Reports[reportType];
let child = useMemo(() => {
return <Report />;
}, [Report]);
says that Report
is an unnecessary dependency. It’s not.
This is because eslint scope .references
does not include JSX. I suspect if you pull in
https://github.com/yannickcr/eslint-plugin-react/blob/master/lib/rules/jsx-uses-vars.js
to your app’s config then this won’t happen. But maybe we should do something in the Hooks plugin itself too (since the others aren’t officially recommended by the React team anyway).
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
useEffect dependency array and ESLint exhaustive-deps rule
Old Answer. Actually the rule is very straightforward: Either pass an array containing all dependencies, or don't pass anything.
Read more >Hooks API Reference - React
This page describes the APIs for the built-in Hooks in React. ... recommend using the exhaustive-deps rule as part of our eslint-plugin-react-hooks package....
Read more >Understanding the React exhaustive-deps linting warning
The obvious answer is to add the count variable to the dependency array. In VS Code, with the ESlint extension, and in other...
Read more >Solve - React Hook useEffect has a missing dependency error.
Note: Don't lie to React about the dependencies you used in the ... when necessary // eslint-disable-next-line react-hooks/exhaustive-deps } ...
Read more >The exhaustive-deps rule has to be treated seriously
It happens when we write useEffect hooks. We intend to just run some code when X changes, but then ESLint tells us to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
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
@yanneves Not quite. See the second code example in https://reactjs.org/docs/hooks-faq.html#how-to-memoize-calculations for more detail on the pattern I’m using.
Duplicate of #18051