Reading and Understanding Exhaustive-Deps Warnings
What you'll learn: How to decode the ESLint messages about dependency arrays so you can fix them confidently.
When the exhaustive-deps rule fires, it's trying to protect you from stale closures and missed updates. The messages can seem cryptic at first, but they follow predictable patterns.
The Three Core Message Types
Missing Dependencies
React Hook useEffect has a missing dependency: 'count'.
Either include it or remove the dependency array.
This means you're using count inside the hook but didn't list it in the dependency array. The fix: add count to the array so the hook re-runs when count changes.
Unnecessary Dependencies
React Hook useEffect has an unnecessary dependency: 'userId'.
Either exclude it or remove the dependency array.
You listed userId in the array but never actually use it inside the hook body. This won't break anything, but it causes unnecessary re-runs. Remove it from the array.
Suggested Fixes
The plugin often suggests: "Update the dependencies array to be: [count, userId]". This is the exact array you should use—copy-paste it. The linter has analyzed your hook body and determined the correct dependencies.
Think of It Like a Recipe
If your recipe (hook body) calls for eggs and flour, your shopping list (dependency array) must include both. Missing ingredients mean stale results. Extra ingredients on your list mean wasted trips to the store.
When you see these warnings, don't disable them—read them carefully. They're pointing to real bugs where your effect won't update when it should, or is updating when it doesn't need to.
Key Takeaway: The exhaustive-deps warning messages tell you exactly which values to add, remove, or keep in your dependency arrays—follow them to avoid stale closures and ensure your hooks behave correctly.