-
Notifications
You must be signed in to change notification settings - Fork 47k
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-plugin-exhaustive-deps] hook wrongly marked as conditional (at exact number of conditionals in FC) #24279
Comments
I will work on this. |
Sure, thanks. |
Fixed in |
Apparently this one is still reproducing |
I am getting something that seems to be related to this; will try to narrow it down. FWIW, I downloaded the repo above and the example given by SanderRonde completes with no error now. In my case having a component with |
I 'solved' it, but the solution is just based on intuition about the difficulties involved in writing static analyzers like esLint rather than any kind of 'fix' to the code. The change I made to fix it was from this (broken, see 3rd line):
to this (fixed, see 3rd line):
|
Similar to SanderRode, the esLint error won't show up unless the output returned from the function component is conditional (even if that condition is awlays false as SanderRode mentioned). |
I'm having the same problem, it's triggered just by meaninglessly moving around condition in the JSX component (AFTER all the hooks are already executed). So is there a way to fix it at all? |
When using an exact number of conditionals before and after a react hook, the
React Hook "hook_name" is called conditionally. React Hooks must be called in the exact same order in every component render
rule is wrongly flagged as being violated. This is a really weird bug and it's kind of hard to explain. Just take a look at the code and watch as ESLint flags the hook as somehow being conditional. While this may seem like a huge edge case, this actually triggered in our code base and caused all hooks in the component to be flagged as conditional.React version: 18.0.0 (doesn't seem to matter)
Steps To Reproduce
yarn
and runyarn eslint app/foo.tsx
.Link to code example: https://github.com/SanderRonde/eslint-hook-bug
Unfortunately I couldn't get it to work online (because of a lack of terminals)
The current behavior
Hook is incorrectly flagged as conditional
The expected behavior
Hook should not be conditional
The text was updated successfully, but these errors were encountered: