-
Notifications
You must be signed in to change notification settings - Fork 47.1k
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(react-hooks/exhaustive-deps) wrong deps with optional chained function calls #18926
Comments
I also have this behavior since upgrading to "eslint-plugin-react-hooks": "4.0.2", from version 4.0.0. In my case: useEffect(() => {
const newSelectedVersion = globalPackage?.version || globalPackage?.versions[0].version;
setSelectedVersion(newSelectedVersion);
}, [globalPackage]); Produce the following warning message:
|
I have similar problem const userEditable = useMemo(
() =>
!formValues?.nodeIds ||
formValues.nodeIds.every(({ id }) => id),
[formValues?.nodeIds],
) Error: const userEditable = useMemo(
() =>
!formValues?.nodeIds ||
formValues.nodeIds.every(({ id }) => id),
[formValues.nodeIds, formValues?.nodeIds],
) It will throw in runtime because |
It also complains about data?.user.theme
|
Guys, every time it complains about the looked up field which is not a function call, the new behavior is probably more correct. In the examples about, if the memoized value depends on @lynxtaa the expression could have been just |
In case of |
Oh my bad. |
This comment has been minimized.
This comment has been minimized.
Relates to #18985, should now be resolved in |
thanks for the fix! |
Re-opening. Bug still occurs: import React, { useMemo } from 'react';
export const Comp = ({ text }) => {
const sliced = useMemo(() => text?.slice(0, 5), [text]);
// ...
}; Plugin suggests changing |
Still happening here too. The fix seems to only work for useEffect(() => {
console.log(a?.b);
}, [a]) // No errors
var c = useMemo(() => {
return a?.b;
}, [a]) // React Hook useMemo has an unnecessary dependency: 'a'. Either exclude it or remove the dependency array If I remove |
Interesting, it's not obvious from the plugin code that |
Happy to keep taking fixes :-) |
still happening in |
Will probably be fixed by #19062 (which is waiting for a merge/release). |
Should be fixed by [email protected] |
Remaining optional chaining problems should be fixed in |
React version: 16.13.1
Steps To Reproduce
Every time optional chaining is used with a function call, the function itself is detected by the rule.
The current behavior
v4.0.1 and above of
eslint-plugin-react-hooks
tells me to change the dep tosomeContext.users?.filter
.The expected behavior
Allow me to keep using
someContext.users
. I can imagine scenarios where I would want the looked up symbol, but that's probably less common than depending on the uniqueness of the instance.Observations
Probably regressed due to #18820, but I'm not sure.
The text was updated successfully, but these errors were encountered: