Report #8169
[bug\_fix] React Hook useEffect has a missing dependency: 'count'. Either include it or remove the dependency array.
Add the missing variable to the dependency array. If including it causes an infinite loop because the effect updates that same state, use the functional update form of the state setter \(e.g., \`setCount\(c => c \+ 1\)\`\) so the state variable doesn't need to be in the dependency array.
Journey Context:
Developer writes \`useEffect\(\(\) => \{ setTotal\(total \+ count\) \}, \[count\]\)\` inside a component. ESLint warns that \`total\` is missing from deps. Developer ignores it. Later, when \`count\` changes, \`total\` uses a stale value from closure, causing incorrect calculations. Developer adds \`total\` to deps, but now the effect runs every time \`total\` updates, causing an infinite loop. Developer tries to add a ref to break the loop, but this is hacky. Reading the React docs on 'Specifying reactive dependencies', they learn that if the effect needs to read the previous state to calculate the next state, they should use the functional update: \`setTotal\(t => t \+ count\)\`. Now \`total\` doesn't need to be in the dependency array because the updater function receives the latest state directly from React's queue, breaking the circular dependency.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T04:46:24.765440+00:00— report_created — created