Course contentsShow
← React
Lesson 222 of 2,3967. Props FundamentalsFree lesson

Passing Objects and Arrays as Props

Complex data structures can be props, but remember each render creates new references unless memoized.

Passing Objects and Arrays as Props

You'll learn: How to pass complex data like objects and arrays as props, and why each render creates new references that can affect performance.

Passing Complex Data Structures

Just like strings and numbers, you can pass objects and arrays as props. You simply wrap them in curly braces:

function UserProfile({ user, hobbies }) {
  return (
    <div>
      <h2>{user.name}</h2>
      <p>Age: {user.age}</p>
      <ul>
        {hobbies.map(hobby => <li key={hobby}>{hobby}</li>)}
      </ul>
    </div>
  );
}

// Using it:
<UserProfile 
  user={{ name: 'Sarah', age: 28 }} 
  hobbies={['reading', 'hiking', 'coding']} 
/>

This works perfectly fine! Pass the data down, destructure it from props, and use it.

The Hidden Problem: New References Every Render

Here's the catch: every time the parent component renders, new objects and arrays are created, even if their contents are identical. JavaScript sees { name: 'Sarah' } from render 1 and { name: 'Sarah' } from render 2 as different objects (different spots in memory).

Think of it like getting a new photocopy of the same document each time — the content is the same, but it's technically a different piece of paper.

This can cause child components to re-render unnecessarily or lose optimization benefits (concepts you'll learn about later with memoization).

The workaround (which you'll learn soon): define objects and arrays outside the component or use techniques to preserve their references across renders.

Key Takeaway: Objects and arrays work as props, but remember that inline object/array literals create new references on every render, which can impact performance in larger applications.