Function Dependencies: The Problem
You'll learn: Why including functions in your dependency array can cause your effects to run on every single render—even when nothing meaningful changed.
The Core Issue
When you define a function inside your component, React creates a brand new function on every render—even if the function's code is identical. Since the dependency array checks equality by reference, that "new" function looks different each time, triggering your effect unnecessarily.
function UserProfile({ userId }) {
const [user, setUser] = useState(null);
// New function created every render!
const fetchUser = () => {
fetch(`/api/users/${userId}`)
.then(res => res.json())
.then(setUser);
};
useEffect(() => {
fetchUser();
}, [fetchUser]); // ⚠️ Effect runs every render
return <div>{user?.name}</div>;
}
Why This Happens
Think of it like photocopies: even if two photocopies show the exact same text, they're different pieces of paper. JavaScript sees each function instance as a unique object in memory, regardless of identical code.
Every render: new fetchUser → dependency changed → effect runs → component re-renders (via setUser) → new fetchUser → infinite loop risk!
The Real-World Impact
This creates unnecessary network requests, performance overhead, and can even cause infinite loops if your effect triggers state updates. The ESLint rule correctly warns you to include fetchUser, but doing so makes things worse.
Key Takeaway: Functions defined during render are recreated every time, making them unstable dependencies that cause effects to re-run unnecessarily—you need strategies to stabilize them or eliminate the dependency entirely.