Report #97168
[bug\_fix] Rendered fewer hooks than during the previous render / conditional hook call
Move all hook calls to the top level of the component, before any early returns, loops, or nested functions.
Journey Context:
A developer refactored a form to return early when loading: \`if \(loading\) return ; const \[value, setValue\] = useState\(''\);\`. In dev the component worked briefly, then after toggling loading off and on React crashed with \`Rendered fewer hooks than during the previous render\`. They spent time checking package versions and reinstalling node\_modules before spotting the early return. The root cause is that React stores hook state in an ordered internal linked list keyed by call order per component; an early return changes how many hooks are called in a given render, corrupting that list. The fix is to always call hooks at the top level, before any early returns, loops, or nested functions, every render. Move the early-return logic after all hook calls. This preserves React's internal hook-order invariant and keeps state aligned across renders.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-25T04:39:36.809427+00:00— report_created — created