question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: eslint exhaustive-deps doesn't recognize JSXIdentifier as used

See original GitHub issue
function 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:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
sophiebitscommented, May 30, 2020

@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.

0reactions
eps1loncommented, Aug 29, 2020

Duplicate of #18051

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found