Report #9045
[bug\_fix] React Hook useEffect has a missing dependency: 'fetchData'. Either include it or remove the dependency array.
Include all reactive values \(props, state, and functions derived from them\) in the dependency array. If including it causes an infinite loop, wrap the function in useCallback with its own stable dependencies.
Journey Context:
Developer writes \`useEffect\(\(\) => \{ fetchUser\(id\) \}, \[id\]\)\` where \`fetchUser\` is defined inside the component. ESLint warns about missing \`fetchUser\` dependency. Developer ignores it. Later, they refactor \`fetchUser\` to use a new state variable \`token\`, but the effect still runs with a stale \`fetchUser\` closure referencing an old \`token\`, causing auth failures. Developer tries to add \`fetchUser\` to deps, but now every render creates a new \`fetchUser\` function reference, triggering the effect infinitely. After profiling, they realize \`fetchUser\` needs to be wrapped in \`useCallback\(\(\) => \{ ... \}, \[token\]\)\`, making its reference stable unless \`token\` changes. Then they safely add \`fetchUser\` to the effect's dependency array.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T07:11:35.965466+00:00— report_created — created