The Inline Array Antipattern
What you'll learn: Why writing [item1, item2] directly in your dependency array causes the same infinite loop problems as inline objects.
The Same Reference Problem in Array Form
Remember how inline objects create new references every render? Arrays work exactly the same way. When you write useEffect(() => { ... }, [userId, userName]) but those values come from an array you create inline, you're creating a brand new array reference on every render—even if the items inside haven't changed.
function UserProfile({ user }) {
useEffect(() => {
console.log('Effect ran');
fetchUserData(user.id, user.name);
}, [user.id, user.name]); // ✅ Good: primitive values
useEffect(() => {
console.log('Effect ran');
fetchUserData(user.id, user.name);
}, [[user.id, user.name]]); // ❌ Bad: inline array
// Creates new [id, name] array every render!
}
Why This Breaks
JavaScript arrays are compared by reference, not by content. [1, 2] !== [1, 2] because they're different objects in memory. So even though user.id and user.name might be stable, wrapping them in [...] creates a fresh array identity every render, triggering your effect infinitely.
This antipattern usually appears when trying to "optimize" by grouping dependencies, but it achieves the opposite.
The Fix
Just list the values directly:
useEffect(() => {
// ...
}, [user.id, user.name]); // Primitives, stable references
Key Takeaway: Never wrap your dependencies in [...] inside the dependency array—arrays are reference types that recreate every render, causing infinite loops just like inline objects.