-
Notifications
You must be signed in to change notification settings - Fork 47.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
eslint-plugin-react-hooks: 'Hook is being called conditionally' error outside condition #16832
Comments
I noticed that for this particular example:
also This particular error is reported when See RulesOfHooks.js line 404 If you abstract the code inside of the In this case, const someObject = { propA: true, propB: false };
const someFunction = (propName) => {
if (propName === true) {
console.log("something");
} else {
console.log("whatever");
}
}
for (const propName in someObject) {
someFunction(propName)
}
const [myState, setMyState] = useState(null); I'm still not sure why. |
@gaearon, I created an MR addressing and fixing this issue (#16853). The main reason this happens is that the value of The reason this happens is because of flawed caching of cyclic paths. So in normal graph traversing, we need the path history as well, but it only takes a list of cyclic elements, and the elements leading to this path are not known. |
This is still an issue with 2.4.0, a little bit simpler repro:
can #16853 be re-openned? |
Merged #16853. |
Do you want to request a feature or report a bug?
BUG (possibly)
What is the current behavior?
The plugin is showing this error:
But I don't think I'm calling any hooks conditionally.
The code:
https://codesandbox.io/s/exciting-bhabha-mqj7q
What is the expected behavior?
The plugin wouldn't show the error in this situation.
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
The text was updated successfully, but these errors were encountered: