Skip to content
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-react-hooks not working inside of Promise #26186

Closed
yuhenghenrycai opened this issue Feb 16, 2023 · 6 comments
Closed

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

yuhenghenrycai opened this issue Feb 16, 2023 · 6 comments
Labels
Resolution: Stale Automatically closed due to inactivity Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@yuhenghenrycai
Copy link

yuhenghenrycai commented Feb 16, 2023

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 yuhenghenrycai added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Feb 16, 2023
@DiFuks
Copy link

DiFuks commented Feb 17, 2023

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

@yuhenghenrycai
Copy link
Author

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

@DiFuks
Copy link

DiFuks commented Feb 20, 2023

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.

@rickhanlonii
Copy link
Member

I think this issue is actually the anon function, which is reported here: #14404

Leaving this open to confirm fixing anon function fixes this.

rickhanlonii added a commit that referenced this issue Jan 29, 2024
These though fail.

Anon default export: #21181
Promise callbacks: #26186
Returning anon functions: #22520
gaearon pushed a commit that referenced this issue Feb 3, 2024
These though fail.

Anon default export: #21181
Promise callbacks: #26186
Returning anon functions: #22520
EdisonVan pushed a commit to EdisonVan/react that referenced this issue Apr 15, 2024
These though fail.

Anon default export: facebook#21181
Promise callbacks: facebook#26186
Returning anon functions: facebook#22520
Copy link

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 github-actions bot added the Resolution: Stale Automatically closed due to inactivity label Apr 28, 2024
Copy link

github-actions bot commented May 5, 2024

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 github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Stale Automatically closed due to inactivity Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

3 participants