5 min
Call hooks only at the top level of a React function, and only from React functions.
Hooks rely on a stable call order so React can associate state with the correct component.
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?