Report #5938
[bug\_fix] Maximum update depth exceeded \(infinite loop\) in useEffect
Remove the object/array from the dependency array that changes identity every render, or use useMemo to stabilize the object reference, or use a primitive value as the dependency
Journey Context:
Developer writes a \`useEffect\` hook depending on an object or array defined inline, such as \`useEffect\(\(\) => \{ fetchData\(filters\) \}, \[filters\]\)\` where \`filters\` is defined as \`const filters = \{ status: 'active' \}\` inside the component. Every re-render creates a new object identity for \`filters\` even if content is identical. React sees a changed dependency and runs the effect again. The effect updates state, causing another render, creating a new \`filters\` object, triggering the effect again—an infinite loop. The browser hangs or shows 'Maximum update depth exceeded' error. The developer tries adding empty deps \`\[\]\` but ESLint warns about missing dependencies. They try \`// eslint-disable-next-line\` but the bug persists. They search 'useEffect infinite loop' and learn that object/array dependencies must have stable identities. The fix is either: \(1\) Move the object definition outside the component if it doesn't depend on props/state, \(2\) Use a primitive dependency like \`filters.status\` instead of the whole object, or \(3\) Wrap the object in \`useMemo\` so it only recreates when specific deps change: \`const filters = useMemo\(\(\) => \(\{ status: 'active' \}\), \[\]\)\`. The developer implements option 3 and the infinite loop stops.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T22:41:36.338114+00:00— report_created — created