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

Props as Dependencies: The Unstable Reference Problem

How parent component creating new objects/functions every render causes child effect loops.

Props as Dependencies: The Unstable Reference Problem

What you'll learn: Why props that are objects or functions can cause your effects to run infinitely, even when the data "looks" the same.

The Core Issue

You've learned that objects and arrays are compared by reference, not by value. Now here's where that bites hard: when a parent component passes an object or function as a prop, it often creates a brand new reference on every render.

If you use that prop in your child component's dependency array, your effect will see a "new" value every time the parent renders — even if the content is identical — triggering an infinite loop.

// Parent
function Parent() {
  const config = { theme: 'dark' }; // ⚠️ New object every render
  return <Child config={config} />;
}

// Child
function Child({ config }) {
  useEffect(() => {
    console.log('Config changed!'); // Runs every render
  }, [config]); // config is always a "new" reference
}

Why This Happens

Every time Parent renders, it creates a fresh { theme: 'dark' } object. Even though it contains the same data, it's a new reference in memory. Your child's effect sees config change from the old reference to the new one and re-runs.

The same problem happens with inline functions:

<Child onUpdate={() => console.log('hi')} />
// New function reference every render

The Solution Pattern

The parent needs to stabilize references using useMemo (for objects/arrays) or useCallback (for functions), which you've already learned.

Key Takeaway: Props that are objects, arrays, or functions become new references on every parent render unless memoized. Always check where your prop dependencies are created, not just where they're used.