Skip to content

[eslint-plugin-react-hooks][RulesOfHooks] handle React.useEffect in addition to useEffect #34076

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Ayc0
Copy link

@Ayc0 Ayc0 commented Aug 1, 2025

Summary

This is a fix for #34074

How did you test this change?

I added tests in the eslint package, and ran yarn jest. After adding the new tests, I have this:

On main On this branch
image image

Changes

  • Add link: to the eslint-plugin-react-hooks pointing to babel-plugin-react-compiler otherwise it wouldn't run locally
  • Add tests to check that we are checking both CallExpression (useEffect(), and MemberExpression (React.useEffect(). To do that, I copied the getNodeWithoutReactNamespace( fn from ExhaustiveDeps.ts to RulesOfHooks.ts

@meta-cla meta-cla bot added the CLA Signed label Aug 1, 2025
@@ -48,6 +48,7 @@
},
"devDependencies": {
"@babel/eslint-parser": "^7.11.4",
"babel-plugin-react-compiler": "link:../../compiler/packages/babel-plugin-react-compiler",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this, jest crashes because it can't resolve babel-plugin-react-compiler:

Before After
image image

I used a link because the compiler is in another yarn workspace, so I don't think I can use other protocols like workspace:

And I used a devDependency to avoid having an impact on the published code

@@ -129,6 +132,24 @@ function isInsideTryCatch(
return false;
}

function getNodeWithoutReactNamespace(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied over from ExhaustiveDeps.ts

return node;
}

function isUseEffectIdentifier(node: Node): boolean {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could have kept the code inlined, but it makes it a bit more readable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant