Report #14582
[bug\_fix] React Hook useEffect has missing dependencies: 'fetchData'. Either include it or remove the dependency array. Alternatively, wrap 'fetchData' definition into its own useCallback\(\) hook. \(react-hooks/exhaustive-deps\)
Include all reactive values \(props, state, functions\) used inside the effect in the dependency array. If adding a function causes infinite loops because its reference changes each render, wrap the function definition in \`useCallback\` with its own stable dependencies, or move the function definition inside the effect.
Journey Context:
Developer creates a search component fetching data based on a query prop. They write \`useEffect\(\(\) => \{ fetchData\(query\) \}, \[query\]\)\` where \`fetchData\` is defined in the same component. ESLint warns that \`fetchData\` is a missing dependency. They ignore it, but later when \`query\` changes, the effect runs with a stale \`fetchData\` closure that references old state from the previous render, causing race conditions. They add \`fetchData\` to the dependency array, but now every keystroke triggers a re-render which redefines \`fetchData\` \(new function reference\), causing the effect to run infinitely and hammer the API. They realize they must wrap \`fetchData\` in \`useCallback\(\(\) => \{ ... \}, \[dispatch\]\)\` to stabilize its reference across renders unless its own dependencies change. After wrapping, they add the now-stable \`fetchData\` to the effect's dependency array. The warnings disappear, the infinite loop stops, and data stays fresh because the effect now correctly tracks all reactive values.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T21:52:44.170485+00:00— report_created — created