1
ReactIntermediate#hooks#refs
Call hooks only at the top level of a React function component or another hook — never inside conditions, loops or nested functions. React relies on a stable call order to match hooks to their state.
// wrong
if (open) { const [x] = useState(0); }
// right
const [x] = useState(0);
if (open) { /* use x */ }