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

Nested Destructuring for Prop Objects

Destructure nested object props directly in parameters, though this can reduce readability if overused.

Nested Destructuring for Prop Objects

What you'll learn: How to destructure nested object properties directly in your component parameters—and when to use (or avoid) this pattern.

The Core Idea

You already know how to destructure props like { name, age }. But what if a prop itself is an object? You might receive user={{ name: "Alice", email: "alice@example.com" }}. Instead of destructuring just user and then accessing user.name, you can destructure into the nested object directly:

// Instead of this:
function UserCard({ user }) {
  return <div>{user.name} - {user.email}</div>;
}

// You can do this:
function UserCard({ user: { name, email } }) {
  return <div>{name} - {email}</div>;
}

The pattern { user: { name, email } } means: "Take the user prop, and immediately pull out its name and email properties."

When It's Helpful

For simple, one-level nesting with just a couple properties, this can reduce visual clutter. You skip the repetitive user. prefix throughout your component.

The Readability Trade-Off

Here's the catch: Nested destructuring can quickly become cryptic. If you have multiple nested levels or many properties, the parameter list turns into a tangled web:

// Hard to read!
function Profile({ user: { name, address: { city, street } }, settings: { theme } }) {
  // ...
}

New developers (and your future self) might struggle to trace where data comes from. Sometimes user.name is clearer than ultra-compact destructuring.

Key Takeaway: Nested destructuring works for simple cases but sacrifices readability when overused—favor clarity over cleverness in your parameter lists.