Common memo Mistakes: Object Props
What you'll learn: How creating new object or array props in the parent component breaks memoization, making React.memo useless.
The Silent Memoization Killer
You've wrapped a child component in React.memo, expecting it to skip re-renders. But it still re-renders every time. The culprit? You're passing a new object or array reference as a prop on every parent render.
const ExpensiveChild = React.memo(({ config }) => {
// Heavy computation here
return <div>{config.name}</div>;
});
function Parent() {
// ❌ BAD: New object created every render
return <ExpensiveChild config={{ name: 'Settings' }} />;
}
Even though config looks identical each time, { name: 'Settings' } is a brand new object reference on every render. React's shallow equality check sees different references and thinks the prop changed—so it re-renders ExpensiveChild anyway.
The Analogy
Imagine you give someone a business card every day. Same info printed on it, but a fresh card each time. They check: "Is this the exact same physical card from yesterday?" No—so they treat it as new information.
Common Scenarios Where This Happens
// ❌ Inline style object
<MemoChild style={{ margin: 10 }} />
// ❌ Array literal
<MemoChild items={[1, 2, 3]} />
// ❌ Inline callback
<MemoChild onClick={() => handleClick()} />
// ❌ Computed object in render
<MemoChild data={{ value: someState * 2 }} />
In every case above, you're creating a new reference during render, breaking memoization.
The Fix
Use useMemo to stabilize the reference, or define static objects outside the component when possible (as covered in previous lessons).
Key Takeaway: Object and array props created inline during render break React.memo because shallow equality compares references, not contents—always stabilize props passed to memoized children.