Report #97667
[bug\_fix] React Hook useEffect has a missing dependency: 'fetchData'
Add the missing dependency to the dependency array, or wrap the function in a \`useCallback\` to stabilize its reference. If the function intentionally should not trigger re-renders, move it inside the effect or use \`// eslint-disable-next-line\` with caution.
Journey Context:
Developer created a \`useEffect\` that called an async function \`fetchData\` defined outside the effect to fetch user data. The linter \(ESLint plugin react-hooks/exhaustive-deps\) warned about missing dependency. Developer initially tried disabling the rule, but later encountered stale closures where \`fetchData\` referenced outdated state. The fix: either define \`fetchData\` inside the effect \(so it's scoped to the effect's closure\) or wrap it with \`useCallback\` and include it in deps. The root cause is that React's exhaustive-deps rule prevents bugs from stale closures by ensuring all reactive values used inside an effect are listed.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-25T15:49:39.159642+00:00— report_created — created