Why Object Literals in Render Cause Re-renders
What you'll learn: How creating objects with {} directly in your JSX causes child components to re-render unnecessarily, even when the data inside hasn't changed.
The JavaScript Identity Problem
Every time you write {} in JavaScript, you create a brand new object reference. Even if two objects contain identical properties, JavaScript sees them as different:
const obj1 = { name: 'Alice' };
const obj2 = { name: 'Alice' };
console.log(obj1 === obj2); // false — different references!
What Happens During Re-renders
When your component re-renders, every line of code runs again. If you pass an object literal as a prop:
function Parent() {
return <Child user={{ name: 'Alice' }} />;
}
Each render creates a new { name: 'Alice' } object. React compares props by reference, so even though the data looks the same, React sees a "different" prop and triggers the child to re-render.
The Analogy
Think of object references like house addresses. Two houses at different addresses can look identical inside, but they're still different houses. React checks addresses (references), not interior design (values).
Why This Matters
If Child is wrapped in React.memo, this pattern defeats its purpose entirely. The memoization check fails because the prop reference changed, forcing a re-render you thought you prevented.
Key Takeaway: Creating object literals ({}) or array literals ([]) directly in JSX props creates new references on every render, causing child components to re-render even when the actual data hasn't changed.