The two rules of hooks
Hooks let function components hold state and interact with the React runtime. Two rules make them work:
- Only call hooks at the top level. Not inside loops, conditions, or nested functions. React identifies each hook by its call order within a render; conditional calls break that order and you'll see
Rendered fewer hooks than expectederrors. - Only call hooks from React functions. Components, or other custom hooks. Not from regular utility functions, not from event handlers' inner async callbacks.
The React 19 compiler (still optional in 2026) loosens the second rule for some patterns, but the first one is hard. Lint with eslint-plugin-react-hooks and the rules-of-hooks rule on β it catches almost every violation.
