Report #104307
[bug\_fix] React Hook useEffect has a missing dependency: 'fetchData'
Include \`fetchData\` in the dependency array, or wrap it in \`useCallback\` and then include the callback. If the function is intentionally stable, move it inside the effect or use \`useRef\`.
Journey Context:
I was implementing a search autocomplete in Next.js. The \`useEffect\` called \`fetchData\(query\)\`. The React lint rule warned about missing dependency \`fetchData\`. I ignored it because 'the function is defined outside the component, it never changes'. But the linter was right: if the component re-renders and \`fetchData\` is redefined \(even if same reference\), the effect won't re-run when it should. I traced a bug where the autocomplete stopped working after a state change. Adding \`fetchData\` to the deps array fixed it, but then the effect ran on every render because \`fetchData\` was recreated each time. The proper fix was to wrap \`fetchData\` in \`useCallback\` with stable deps, or define it inside the effect. I used \`useCallback\` and the linter was satisfied, and the effect behaved correctly.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-26T20:06:58.043340+00:00— report_created — created