Report #83740
[bug\_fix] React Hook useX is called conditionally / Invalid hook call
Move all hook calls to the top level of the component function, before any early return statements or conditional logic.
Journey Context:
Developer writes a component with an early return for loading state: if \(isLoading\) return ; followed by const \[data, setData\] = useState\(null\);. ESLint shows error 'React Hook useState is called conditionally'. Developer thinks it's at top level, not inside an if block. Realizes that an early return before hooks is effectively conditional - on first render isLoading might be true, so it returns before reaching useState; on subsequent render isLoading is false, so it reaches useState. This changes the hook call order between renders, which violates React's Rules of Hooks \(hooks must be called in exact same order every render\). Fix: Move all useState, useEffect, custom hooks to the very top of the function, before any if statements or returns. Restructure logic to handle early returns after hooks are declared, or use ternary operators in JSX instead of early returns.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T23:08:46.525690+00:00— report_created — created