Skip to content

Bug: eslint-plugin-react-hooks incorrectly flags useSomething() in loop, while allowing use() in React 19 #32789

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

Closed
JangHwanPark opened this issue Mar 29, 2025 · 2 comments
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@JangHwanPark
Copy link

React version: 19.0.0
eslint-plugin-react-hooks: 5.3.1

Steps To Reproduce

  1. Create a custom hook (e.g. useSomething)
  2. Call it inside a loop

Link to code example:

function App() {
  for (const item of items) {
    useSomething(item); // error
  }
}
function App() {
  for (const item of items) {
    use(item); // no error
  }
}

The current behavior

Calling useSomething() inside a loop triggers a lint error:

React Hook "useSomething" may be executed more than once. Possibly because it is called in a loop.

But calling use() inside the same loop does not trigger an error.

The expected behavior

React 19 allows use(promise) to be called in a loop, but eslint-plugin-react-hooks only allows use(), not custom hooks like useSomething().

Since React 19’s implementation no longer treats use() as special by name, ESLint should ideally match this behavior and allow user-defined useSomething() calls in the same pattern, or clearly define why use() is a special case.

@JangHwanPark JangHwanPark added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Mar 29, 2025
@JangHwanPark JangHwanPark changed the title Bug: Bug: eslint-plugin-react-hooks incorrectly flags useSomething() in loop, while allowing use() in React 19 Mar 29, 2025
@josephsavona
Copy link
Contributor

Thanks for posting. This is definitely confusing but use() is a function, not a hook. Hence it doesn't have to follow the rules of Hooks, and it's okay to call use() in a loop while it's not ok to call hooks in loops. You can read more about use here: https://react.dev/reference/react/use

@JangHwanPark
Copy link
Author

Thank you for the clarification! Since use() is not considered a Hook and is intentionally exempt from the Rules of Hooks, the current lint behavior is expected. Closing this as it's working as intende

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

2 participants