-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add react-hooks/exhaustive-deps lint rule #20936
Conversation
@youknowriad I seem to recall that you had some objections to this previously? |
There is PR where we @youknowriad added missing dependencies to the usage of custom hooks: #19044. I can’t find the discussion about the rule you propose but it might have something to do with giving false negatives for referenced pure functions and similar cases that the rule doesn’t process (or used to) properly. |
I'm not against adding this rule but I'm pretty certain this breaks a lot of existing hooks, so we need to be careful when "fixing" the lint error to ensure the desired behavior is retained. Sometimes it means refactoring the code I believe. |
@@ -30,5 +30,6 @@ module.exports = { | |||
'react/prop-types': 'off', | |||
'react/react-in-jsx-scope': 'off', | |||
'react-hooks/rules-of-hooks': 'error', | |||
'react-hooks/exhaustive-deps': 'warn', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it's 'warn'
for the purpose of initial discussion, but we shouldn't want to introduce this to the codebase as a warning. It will be ignored.
Related: #18458
Closing for now. I am not going to pursue merging this PR for the time being and we can always reopen later. |
Description
As mentioned in the docs, when using hooks it's worth checking if deps array is exhaustive. This is done by react-hooks/exhaustive-dep eslint rule. This PR adds that rule. It immediately detected numerous violations, most of the time with a pretty good explanation:
Let's use this PR as a place to discuss whether or not we should be using that rule.
How has this been tested?
Tested locally.
Types of changes
Non-breaking changes
Checklist: