react icon indicating copy to clipboard operation
react copied to clipboard

Bug: eslint-plugin-react-hooks not working inside of Promise

Open yuhenghenrycai opened this issue 2 years ago • 5 comments

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

yuhenghenrycai avatar Feb 16 '23 23:02 yuhenghenrycai

How do you use hooks inside promises? Hooks should only be called in the body of components

DiFuks avatar Feb 17 '23 08:02 DiFuks

@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...

yuhenghenrycai avatar Feb 17 '23 22:02 yuhenghenrycai

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.

DiFuks avatar Feb 20 '23 09:02 DiFuks

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.

rickhanlonii avatar Jan 29 '24 16:01 rickhanlonii

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!

github-actions[bot] avatar Apr 28 '24 17:04 github-actions[bot]

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!

github-actions[bot] avatar May 05 '24 18:05 github-actions[bot]