Course contentsShow
← React
Lesson 1023 of 2,39626. Rules of Hooks Deep DiveFree lesson

Auto-Fix Behavior and Pitfalls

How the plugin's auto-fix can add dependencies automatically, and when to review its suggestions carefully.

Auto-Fix Behavior and Pitfalls

What you'll learn: How the ESLint plugin can automatically add missing dependencies to your arrays—and when you need to carefully review what it suggests.

The eslint-plugin-react-hooks doesn't just warn you about missing dependencies; it can auto-fix them for you. When you see an exhaustive-deps warning, your editor (if configured) can automatically insert the missing variable into your dependency array with a single command or keystroke.

How Auto-Fix Works

When the plugin detects a value used inside your useEffect, useCallback, or useMemo that's missing from the dependency array, it offers to add it. Hit "fix" and—boom—the variable appears in the array. This is incredibly convenient and catches many legitimate oversights.

The Pitfall: Blind Trust

The problem? Auto-fix doesn't understand your intent. It follows the rules mechanically. If you have a problem with infinite loops, stale closures, or poor hook design, auto-fix will happily add dependencies that create new problems:

  • Infinite loops: Auto-fix adds an object/array that's recreated every render, causing the effect to run constantly
  • Wrong solution: The real issue might be needing useCallback or functional updates, but auto-fix just adds the problematic dependency
  • Masking design flaws: Sometimes the warning signals that your logic needs restructuring, not just more dependencies

Review Before Accepting

Think of auto-fix like autocorrect on your phone: it's usually right, but sometimes hilariously wrong. Always read what it's adding. Ask yourself: "Will this dependency change every render? Is this actually what I want?"

Key Takeaway: Auto-fix is a helpful assistant that catches missing dependencies quickly, but you must review its suggestions—blindly accepting can introduce bugs or infinite loops that the linter can't detect.