Report #97672
[bug\_fix] Error: 'Invalid hook call. Hooks can only be called inside of the body of a function component.'
Ensure you are not calling hooks inside conditions, loops, or after early returns. Move all hook calls to the top level of the component, and verify that you are not using hooks outside of a React component \(e.g., in a regular function or class\).
Journey Context:
Developer was refactoring a component and accidentally placed a \`useState\` call inside an \`if\` block that checked a prop. The error appeared only when the condition was false, because the hook call was skipped. Developer spent hours checking for mismatched React versions \(e.g., two copies of React in node\_modules\), but the actual issue was the conditional hook. The fix: moving the \`useState\` call to the top of the component, before the condition. The root cause is that React relies on the order of hook calls to maintain state between renders; conditional hooks break that invariant.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-25T15:50:16.430743+00:00— report_created — created