Report #11765
[bug\_fix] React Hook useEffect has a missing dependency: 'someVar'. Either include it or remove the dependency array
Include all reactive values \(props, state, derived values\) used inside the \`useEffect\` callback in the dependency array. If the effect shouldn't re-run when a variable changes, use a ref or move the variable outside the component.
Journey Context:
Developer builds a search filter that fetches results when the \`query\` prop changes. They write \`useEffect\(\(\) => \{ fetchResults\(query\); \}, \[\]\)\` with an empty dependency array, intending it to run only on mount. During testing, they notice that when the parent updates the \`query\` string, the effect never re-runs and the results remain stale. They add \`console.log\(query\)\` inside the effect and confirm it logs the initial query only. They check the ESLint warnings and see 'React Hook useEffect has a missing dependency: query'. They initially ignore it, thinking it's just a warning. They later realize that JavaScript closures capture the value of \`query\` at the time the effect function is defined. Since the effect never re-subscribes, it forever sees the stale \`query\` value from the first render. The fix is to add \`query\` to the dependency array: \`\}, \[query\]\)\`. Now React re-runs the effect whenever \`query\` changes, ensuring the closure always has access to the current value. If they needed to avoid re-fetching on every render due to unstable object references, they would use \`useMemo\` or \`useCallback\` to stabilize the dependencies.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T14:15:13.521488+00:00— report_created — created