-
Notifications
You must be signed in to change notification settings - Fork 46.4k
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
[eslint-plugin-react-hooks] Report constant constructions #19590
Merged
Commits on Aug 11, 2020
-
[eslint-plugin-react-cooks] Report constant constructions
The dependency array passed to a React hook can be thought of as a list of cache keys. On each render, if any dependency is not `===` its previous value, the hook will be rerun. Constructing a new object/array/function/etc directly within your render function means that the value will be referentially unique on each render. If you then use that value as a hook dependency, that hook will get a "cache miss" on every render, making the dependency array useless. This can be especially dangerous since it can cascade. If a hook such as `useMemo` is rerun on each render, not only are we bypassing the option to avoid potentially expensive work, but the value _returned_ by `useMemo` may end up being referentially unique on each render causing other downstream hooks or memoized components to become deoptimized.
Configuration menu - View commit details
-
Copy full SHA for bc36370 - Browse repository at this point
Copy the full SHA bc36370View commit details
Commits on Aug 12, 2020
-
Configuration menu - View commit details
-
Copy full SHA for 450cdfd - Browse repository at this point
Copy the full SHA 450cdfdView commit details -
Don't give an autofix of wrapping object declarations
It may not be safe to just wrap the declaration of an object, since the object may get mutated. Only offer this autofix for functions which are unlikely to get mutated. Also, update the message to clarify that the entire construction of the value should get wrapped.
Configuration menu - View commit details
-
Copy full SHA for 75fcb35 - Browse repository at this point
Copy the full SHA 75fcb35View commit details -
Configuration menu - View commit details
-
Copy full SHA for 4b6e20e - Browse repository at this point
Copy the full SHA 4b6e20eView commit details
Commits on Aug 13, 2020
-
Configuration menu - View commit details
-
Copy full SHA for e0ca072 - Browse repository at this point
Copy the full SHA e0ca072View commit details -
Configuration menu - View commit details
-
Copy full SHA for 4dc35db - Browse repository at this point
Copy the full SHA 4dc35dbView commit details -
Configuration menu - View commit details
-
Copy full SHA for eaa2aff - Browse repository at this point
Copy the full SHA eaa2affView commit details -
Configuration menu - View commit details
-
Copy full SHA for 2b7ae4b - Browse repository at this point
Copy the full SHA 2b7ae4bView commit details -
Configuration menu - View commit details
-
Copy full SHA for 31f75cd - Browse repository at this point
Copy the full SHA 31f75cdView commit details
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.