Report #57749
[bug\_fix] Maximum update depth exceeded or browser freezing due to infinite re-render loops in useEffect when state updates trigger the effect again.
Use functional state updates 'setState\(prev => ...\)' to avoid depending on the current state value in the dependency array, or remove the state from the dependency array if using functional updates. Alternatively, use useMemo or useCallback to stabilize object references passed to the effect. Root cause: Including a state value in the useEffect dependency array causes the effect to re-run when that state changes; if the effect also sets that state, it creates an infinite loop. React's functional update form allows updating state without reading the current value from closure, breaking the dependency cycle.
Journey Context:
You write a counter that increments automatically: 'useEffect\(\(\) => \{ setCount\(count \+ 1\); \}, \[count\]\);'. The browser tab immediately freezes or shows 'Maximum update depth exceeded'. You open the console and see thousands of log statements. You realize that updating count triggers the effect \(because count is in deps\), which updates count again. You search React docs for useEffect dependencies. You find the section on removing dependencies. You refactor to use the functional update form: 'useEffect\(\(\) => \{ setCount\(c => c \+ 1\); \}, \[\]\);' with an empty dependency array. The loop stops because the effect no longer depends on the external count variable; it uses the internal updater function. You understand that the dependency array must include all reactive values read inside the effect, but functional updates allow you to avoid reading the value from scope.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T03:25:11.866747+00:00— report_created — created