Course contentsShow
← React
Lesson 620 of 2,39617. Common useEffect MistakesFree lesson

When to Ignore the Exhaustive-Deps Warning

Rarely valid: when you understand the closure and intentionally want stale values (document why).

When to Ignore the Exhaustive-Deps Warning

You'll learn: The rare, valid cases where you can intentionally ignore the exhaustive-deps ESLint warning — and why documentation is critical.

The Extremely Rare Exception

You've learned that the exhaustive-deps rule is there to protect you from stale closure bugs. But there are edge cases where you understand the closure behavior and intentionally want stale values captured at a specific moment in time.

This is not "the rule is annoying, so I'll disable it." This is "I have a specific, documented reason to capture these values once and never update them."

A Legitimate (But Rare) Example

Imagine logging the initial value of a prop when the component first mounts, regardless of future changes:

function AnalyticsLogger({ userId }) {
  useEffect(() => {
    // We ONLY want the userId from the first render
    logInitialUser(userId);

    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []); // Intentionally empty — we want stale userId

  return <div>User Profile</div>;
}

Here, you're intentionally creating a stale closure. You want the userId from mount, not the latest one.

The Golden Rule: Always Document Why

If you disable the warning, you must leave a comment explaining your reasoning. Future you (or your teammates) need to understand this wasn't a mistake:

// We intentionally capture userId at mount time only
// to log the initial session start. Updates are handled
// by a separate subscription effect.
// eslint-disable-next-line react-hooks/exhaustive-deps

Without this comment, someone will "fix" your code and introduce the bug you were avoiding.

Key Takeaway: Ignoring exhaustive-deps is valid only when you understand closures deeply and have a documented reason to capture stale values — and this should be vanishingly rare in real codebases.