Report #10451
[bug\_fix] React Hook 'useX' is called conditionally
Move all Hook calls to the top level of the component function, before any early return statements or conditional logic, ensuring hooks are called in the same order on every render.
Journey Context:
Developer refactors a class component to a function component. They write: \`if \(\!user\) return null; const \[data, setData\] = useState\(null\);\`. React throws 'React Hook useState is called conditionally'. Developer doesn't understand that React relies on hook call order to match state to calls. They try moving the hook inside the if block, same error. They try using a ternary operator. The fix requires understanding that hooks must run unconditionally. They must move the \`useState\` call to before the \`if \(\!user\)\` check, and handle the early return after the hooks, or conditionally render the component that uses hooks separately. This ensures React's internal linked list of hooks stays consistent between server and client renders.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T10:45:18.966669+00:00— report_created — created