Course contentsShow
← React
Lesson 916 of 2,39624. React.memoFree lesson

When Props Are Objects: Reference Equality Matters

Object and array props must maintain stable references or memo won't prevent re-renders.

When Props Are Objects: Reference Equality Matters

You'll learn: Why passing object or array props can break React.memo's optimization, even when the object's contents don't change.

The Core Problem

React.memo uses shallow equality to compare props. For primitives like strings or numbers, this works perfectly—React checks if the values are the same. But for objects and arrays, React checks if they're the same reference in memory, not whether their contents match.

This means if you create a new object on every render (even with identical properties), React.memo will see it as "different" and re-render the memoized component anyway.

Why This Happens

JavaScript creates a new reference every time you write an object literal or array literal. Even if two objects look identical, they're different references:

const obj1 = { name: "Alice" };
const obj2 = { name: "Alice" };
console.log(obj1 === obj2); // false! Different references

When a parent component re-renders and creates a new object inline to pass as a prop, React.memo compares the old object reference to the new object reference, sees they're different, and triggers a re-render—even though the data inside is identical.

The Analogy

Think of object references like house addresses. Even if two houses are identically furnished inside, they're still different houses with different addresses. React.memo only checks addresses, not the furniture.

Key Takeaway: When passing objects or arrays as props to memoized components, you must maintain stable references (using useMemo) or React.memo will always re-render, defeating its purpose.