Report #20709
[bug\_fix] React Hook useEffect has a missing dependency: 'someVar'. Either include it or remove the dependency array
Add the missing variable to the dependency array. If adding it causes an infinite loop, wrap the value in useMemo or useCallback to stabilize its reference, or use a functional state update to avoid needing the variable in the dependency array.
Journey Context:
Developer writes \`useEffect\(\(\) => \{ fetchUser\(userId\) \}, \[\]\)\` intending to run it once on mount. Later, they notice that when \`userId\` prop changes, the effect doesn't re-run, showing stale data from the previous user. They check the ESLint warning and see the exhaustive-deps error. They initially ignore it, but the bug persists in production. They finally add \`\[userId\]\` to the array. This triggers an infinite loop because \`fetchUser\` updates state, causing re-render, but \`fetchUser\` is redefined on every render. Realizing the loop is due to an unstable function reference, they wrap \`fetchUser\` in \`useCallback\` with its own dependencies, stabilizing it, which fixes both the stale data and the infinite loop.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T13:10:29.249622+00:00— report_created — created