react-hooks/exhaustive-deps ⚛️ React

React Hook useEffect has a missing dependency (react-hooks/exhaustive-deps)

ESLint warns that the effect reads a value that isn’t in its dependency array, so it may use a stale value.

Seen on: React

Meaning

Effects capture values from the render they were created in. Leaving a dependency out means the effect won’t re-run when it changes. Blindly adding a function or object dependency can cause infinite loops, so restructure instead.

Common causes

  • Prop/state used in the effect but not listed
  • Function defined in the component used inside the effect
  • Object/array dependency recreated every render

⚡ Quick fix

  1. Add the missing dependency if re-running is correct
  2. Move the function inside the effect, or wrap it in useCallback
  3. Use the functional state update (setCount(c => c + 1)) to drop a state dependency
  4. Memoise objects with useMemo

Detailed fix by platform

React

  1. Move the function inside the effect:
    jsx
    useEffect(() => {
      async function load() {
        const res = await fetch(`/api/users/${userId}`);
        setUser(await res.json());
      }
      load();
    }, [userId]);          // complete and stable

How to diagnose

  1. Dependency — Which value is named?
  2. Stability — Does it change every render?
  3. Intent — Should the effect re-run when it changes?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.