Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
sophiebits opened this issue May 16, 2020 · 5 comments
Closed

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

sophiebits opened this issue May 16, 2020 · 5 comments

Comments

@sophiebits
Copy link
Collaborator

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

@muskeinsingh
Copy link

Can I pick this up?

@yanneves
Copy link
Contributor

@sophiebits would what you're doing not be better solved by React.memo() instead?

const Child = React.memo(() => <Report />)

https://reactjs.org/docs/react-api.html#reactmemo

@sophiebits
Copy link
Collaborator Author

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

@stale
Copy link

stale bot commented Aug 29, 2020

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

@stale stale bot added the Resolution: Stale Automatically closed due to inactivity label Aug 29, 2020
@eps1lon
Copy link
Collaborator

eps1lon commented Aug 29, 2020

Duplicate of #18051

@eps1lon eps1lon marked this as a duplicate of #18051 Aug 29, 2020
@eps1lon eps1lon closed this as completed Aug 29, 2020
@eps1lon eps1lon added Resolution: Duplicate and removed Resolution: Stale Automatically closed due to inactivity labels Aug 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants