Ref Values Don't Belong in Dependencies
What you'll learn: Why refs created with useRef should never be included in your useEffect dependency array.
The Core Idea
When you create a ref with useRef, you get back a stable object that persists across renders. Importantly, mutating a ref's .current property does not trigger a re-render. Because of this, refs are fundamentally different from state or props—they're stable references that don't participate in React's reactivity system.
Since the dependency array is all about detecting when things change to re-run your effect, and refs don't signal changes, they don't belong there.
Why This Matters
const countRef = useRef(0);
useEffect(() => {
// ❌ Wrong: Including countRef
console.log('Effect ran');
}, [countRef]);
The problem here: countRef is the same object on every render. React compares dependencies by reference, and the ref object never changes—only its .current value does. So including it is meaningless.
// ✅ Correct: Omit the ref entirely
useEffect(() => {
console.log('Effect ran, count is', countRef.current);
}, []); // countRef not needed
The Analogy
Think of a ref like a box that sits on a shelf. The box itself never moves (stable reference), but you can reach inside and change what's in it (.current) without anyone noticing. Your effect watching "has the box changed?" will always see the same box—it can't detect the contents changing.
Key Takeaway: Refs are stable objects that don't trigger renders, so they're safe to omit from dependency arrays. Only include values that should cause your effect to re-run when they change.