Report #5188
[bug\_fix] Maximum update depth exceeded or Stale closure in useEffect
Include all reactive values \(props, state, functions\) used in useEffect in the dependency array. If a function dependency causes infinite loops, memoize it with \`useCallback\`, or if an object, memoize with \`useMemo\`. If the effect should only run once on mount, ensure no reactive values are used inside without proper handling.
Journey Context:
Developer writes \`useEffect\(\(\) => \{ fetchData\(userId\); \}, \[\]\)\` but \`userId\` comes from props. They see stale data when \`userId\` changes. They add \`userId\` to deps: \`\[userId\]\`. Then they add \`fetchData\` function to deps, but \`fetchData\` is defined in the component body, causing a new reference every render, triggering infinite loop "Maximum update depth exceeded". They try to remove deps to stop the loop, causing staleness. They finally understand they need to wrap \`fetchData\` in \`useCallback\` with its own dependencies, then include the stable callback in the effect deps. Or they move \`fetchData\` inside the effect.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T20:48:38.905557+00:00— report_created — created