Rules of Hooks

The two rules for hooks: call them only at the top level, never in conditions, loops or nested functions, and only from React components or custom hooks.

In more detail

Breaking them makes React pair hooks with the wrong stored state. The eslint-plugin-react-hooks plugin catches violations, and to run a hook conditionally you move the condition inside it, such as an early return inside an Effect.

Related terms

Taught in

References