react
react copied to clipboard
Bug: eslint-plugin-react-hooks not working inside of Promise
React version: "eslint-plugin-react-hooks": "^4.2.0"
Link to code example: rule of hook(eslint-plugin-react-hooks) did not fire when it is inside of a Promise block. Please find the detailed explanation in example code below. thx https://codesandbox.io/s/romantic-austin-uyoiyj?file=/src/generateSomething.js
How do you use hooks inside promises? Hooks should only be called in the body of components
@DiFuks that is right, but I was not aware of it when I code it. And I think eslint-plugin-react-hooks
should have caught the error. Can you update the code for eslint-plugin-react-hooks
to make sure the bug won't fall through the crack?
To be specific, the hook I was trying to access inside of promise is useRelayEnvironment
, which is about injecting the relay environment to handle the GraphQL query/mutation. Because Eslint did not capture this issue, I merged the bug into production until users complained...
This is described in the documentation and any tutorials. I'm not the maintainer of react, but it seems to me that the plugin should not check such things.
I think this issue is actually the anon function, which is reported here: https://github.com/facebook/react/issues/14404
Leaving this open to confirm fixing anon function fixes this.
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!