Course contentsShow
← React
Lesson 2242 of 2,39649. Performance: Identifying ProblemsFree lesson

Array Literals and .map() Return Values

How `items.map(item => ({ ...item }))` creates new objects and when it matters for child components.

Array Literals and .map() Return Values

What you'll learn: How creating new objects inside .map() can trigger unnecessary child re-renders, and when it actually matters.

The Problem with Inline Object Creation in .map()

You've just learned about object literals causing re-renders. The same issue appears—often at scale—when rendering lists:

// This creates brand new objects on every render
<div>
  {items.map(item => (
    <ExpensiveChild key={item.id} data={{ ...item }} />
  ))}
</div>

Every render, .map() executes and { ...item } creates a fresh object for each item. If ExpensiveChild is memoized with React.memo(), it receives a new data reference every time—even when item hasn't changed—defeating the memo entirely.

When It Actually Matters

This only causes performance problems when:

  1. The child component is expensive to render (complex calculations, many DOM nodes)
  2. The child is memoized (otherwise it re-renders anyway when the parent does)
  3. The list is long enough that cumulative waste becomes measurable

For small lists or cheap components, the overhead of creating new objects is negligible.

What to Look For

Check the Profiler when a list parent re-renders. If all children re-render despite unchanged data, inspect how you're passing props:

// ❌ New objects every render
items.map(item => <Child data={{ ...item }} />)
items.map(item => <Child style={{ color: 'red' }} />)

// ✅ Stable references (if item itself hasn't changed)
items.map(item => <Child data={item} />)

Key Takeaway: .map() callbacks that create new objects ({ ...item }, inline styles, etc.) break memoization for every item in the list—but only optimize if profiling shows it matters.