Report #15496
[bug\_fix] Maximum update depth exceeded or infinite re-render loop in useEffect
Use functional state updates \(setState\(prev => ...\)\) to avoid needing the state variable in the dependency array, or use useMemo to stabilize object/array references that change on every render.
Journey Context:
Developer writes a useEffect that sets state based on the current state and includes that state variable in the dependency array. The component enters an infinite loop: the effect runs, updates state, triggers a re-render, and the effect runs again because the dependency changed. The developer attempts to remove the dependency to break the loop, but ESLint warns about missing dependencies. They search the React documentation and discover the functional update form of setState, which accepts a function receiving the previous state and returns the new state, eliminating the need to include the state variable in the effect dependencies. Alternatively, they learn to use useMemo for props that are objects to keep referential equality stable across renders, breaking the infinite cycle.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T00:18:17.990782+00:00— report_created — created