Interview Horizon

What are the Rules of Hooks?

foundation

5 min

Short answer

Call hooks only at the top level of a React function, and only from React functions.

Explanation

Hooks rely on a stable call order so React can associate state with the correct component.

Interview answer example

I keep hooks at the top of the function and extract conditionals into custom hooks instead of wrapping hook calls.

What are the Rules of Hooks, and why do they exist?