Report #9869
[bug\_fix] Maximum update depth exceeded \(infinite loop\) in useEffect
Remove the changing state or object reference from the dependency array. Use functional state updates setState\(prev => prev \+ 1\) to avoid needing the current state in deps, or memoize objects/callbacks with useMemo/useCallback to stabilize references across renders.
Journey Context:
Developer writes: useEffect\(\(\) => \{ setCount\(count \+ 1\) \}, \[count\]\). On component mount, the effect runs, increments count, which triggers a re-render. Because count changed, the effect runs again immediately, creating an infinite loop that freezes the browser with "Maximum update depth exceeded". Developer tries removing dependencies entirely \(\[\]\) but gets stale closure where count is always 0. Tries adding eslint-disable-next-line react-hooks/exhaustive-deps, which silences the linter but keeps the loop. Realizes the dependency array is correct to detect changes, but the state update shouldn't depend on the current render's value. Refactors to functional update: setCount\(c => c \+ 1\). Now the effect doesn't need count in its dependencies \(or can have empty deps if only runs on mount\), breaking the loop because the dependency array is stable. Alternatively, for object dependencies causing loops, uses useMemo to keep object reference stable.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T09:16:36.868920+00:00— report_created — created