React Props with Objects

React props can contain many different types of JavaScript values, including strings, numbers, booleans, arrays, functions, JSX, and objects.

Objects are especially useful when several related values belong to the same entity.

For example, a user might have:

name
role
location
experience

Instead of passing each value separately, you can group them into one object and pass that object as a prop.

For example:

function App() {
  const user = {
    name: "Karimulla",
    role: "Frontend Developer",
    location: "Hyderabad"
  };

  return <Profile user={user} />;
}

The Profile component receives the complete object:

function Profile({ user }) {
  return (
    <div>
      <h2>{user.name}</h2>
      <p>{user.role}</p>
      <p>{user.location}</p>
    </div>
  );
}

Objects allow related information to travel together as a single prop.

What Does Props with Objects Mean?

When you pass an object as a prop, the object becomes the value of that prop.

For example:

<User
  user={{
    name: "Karimulla",
    role: "Frontend Developer"
  }}
/>

Here, user is the prop name and the value is an object.

Conceptually, the component receives:

{
  user: {
    name: "Karimulla",
    role: "Frontend Developer"
  }
}

The child can then access the object’s properties.

function User({ user }) {
  return <h2>{user.name}</h2>;
}

The basic flow is:

Object
   ↓
Passed as Prop
   ↓
Child Component
   ↓
Read Object Properties
   ↓
Render UI

Why Pass Objects as Props?

Objects are useful when multiple values naturally belong together.

Consider a course:

Course
├── title
├── level
├── lessons
├── duration
└── progress

You could pass every value separately:

<Course
  title="React"
  level="Beginner"
  lessons={40}
  duration="8 Weeks"
  progress={75}
/>

Or group the related information into an object:

const course = {
  title: "React",
  level: "Beginner",
  lessons: 40,
  duration: "8 Weeks",
  progress: 75
};

<Course course={course} />

The second approach can be useful when the values represent one complete entity.

Creating an Object Before Passing It

The cleanest approach is often to create the object first.

function App() {
  const course = {
    title: "React",
    level: "Beginner",
    lessons: 40,
    duration: "8 Weeks",
    progress: 75
  };

  return <Course course={course} />;
}

The child receives the object:

function Course({ course }) {
  return (
    <div>
      <h2>{course.title}</h2>
      <p>Level: {course.level}</p>
      <p>Lessons: {course.lessons}</p>
      <p>Duration: {course.duration}</p>
      <p>Progress: {course.progress}%</p>
    </div>
  );
}

This keeps the parent and child responsibilities clear.

The parent owns the data, while the child uses that data to create the UI.

Passing an Inline Object

You can also create the object directly inside JSX.

<User
  user={{
    name: "Karimulla",
    role: "Frontend Developer",
    location: "Hyderabad"
  }}
/>

Notice the double curly braces.

The outer braces tell JSX that you are providing a JavaScript expression.

The inner braces create the JavaScript object.

user={{
  name: "Karimulla",
  role: "Frontend Developer"
}}
     ↑
JavaScript object

For larger objects, creating the object in a variable is usually easier to read.

Reading Object Props

Suppose the parent passes:

const user = {
  name: "Karimulla",
  role: "Frontend Developer",
  experience: 1
};

<User user={user} />

The child can read the object:

function User({ user }) {
  return (
    <div>
      <h2>{user.name}</h2>
      <p>{user.role}</p>
      <p>{user.experience} year experience</p>
    </div>
  );
}

The pattern is:

user.name
user.role
user.experience

The first part identifies the object.

The second part identifies the property.

Destructuring an Object Prop

You can destructure the object prop first.

function User({ user }) {
  const {
    name,
    role,
    experience
  } = user;

  return (
    <div>
      <h2>{name}</h2>
      <p>{role}</p>
      <p>{experience} year experience</p>
    </div>
  );
}

Now you can use:

name
role
experience

instead of:

user.name
user.role
user.experience

This can improve readability when you use several properties from the object.

Nested Object Destructuring

JavaScript also allows nested destructuring.

For example:

function User({ user: { name, role } }) {
  return (
    <div>
      <h2>{name}</h2>
      <p>{role}</p>
    </div>
  );
}

This extracts name and role directly from the user object.

However, nested destructuring can become harder to read when objects become deeply nested.

For beginners, this approach is often easier to understand:

function User({ user }) {
  const { name, role } = user;

  return (
    <div>
      <h2>{name}</h2>
      <p>{role}</p>
    </div>
  );
}

Choose the version that makes the component easiest to understand.

Passing Objects with Different Data Types

An object can contain many different types of values.

For example:

const course = {
  title: "React",
  lessons: 40,
  progress: 75,
  available: true,
  topics: [
    "JSX",
    "Props",
    "State"
  ]
};

You can pass the entire object:

<Course course={course} />

The child can access each property:

function Course({ course }) {
  return (
    <div>
      <h2>{course.title}</h2>

      <p>Lessons: {course.lessons}</p>

      <p>Progress: {course.progress}%</p>

      <p>
        {course.available
          ? "Available"
          : "Unavailable"}
      </p>

      <ul>
        {course.topics.map((topic) => (
          <li key={topic}>{topic}</li>
        ))}
      </ul>
    </div>
  );
}

One object can therefore contain strings, numbers, booleans, arrays, and other objects.

Passing Nested Objects

Objects can contain other objects.

For example:

const user = {
  name: "Karimulla",
  role: "Frontend Developer",
  address: {
    city: "Hyderabad",
    country: "India"
  }
};

Pass it to the component:

<User user={user} />

The child can access nested properties:

function User({ user }) {
  return (
    <div>
      <h2>{user.name}</h2>
      <p>{user.role}</p>
      <p>{user.address.city}</p>
      <p>{user.address.country}</p>
    </div>
  );
}

The dot notation allows you to move through the object hierarchy.

user
 ├── name
 ├── role
 └── address
      ├── city
      └── country

Passing Objects from State

Objects are frequently stored in React state and passed as props.

For example:

function App() {
  const [user, setUser] = useState({
    name: "Karimulla",
    role: "Frontend Developer"
  });

  return <Profile user={user} />;
}

The child reads the object:

function Profile({ user }) {
  return (
    <div>
      <h2>{user.name}</h2>
      <p>{user.role}</p>
    </div>
  );
}

If the parent updates the state with a new object, the child can receive the updated object through props.

This pattern is common in interactive applications.

Updating Object Data

When an object is stored in state, don’t mutate the existing object directly.

Avoid:

user.name = "John";

Instead, create a new object when updating state:

setUser({
  ...user,
  name: "John"
});

The spread syntax copies the existing properties and replaces the name property with the new value.

This matters because React state updates should be performed through the appropriate state setter rather than by directly mutating the existing object.

Passing Objects to Reusable Components

Objects are particularly useful when building reusable components for entities such as:

  • Users
  • Courses
  • Products
  • Articles
  • Tutorials
  • Orders
  • Posts
  • Profiles

For example:

const product = {
  name: "Wireless Keyboard",
  price: 49,
  category: "Accessories",
  rating: 4.5
};

<ProductCard product={product} />

The component can use the object:

function ProductCard({ product }) {
  return (
    <article>
      <h2>{product.name}</h2>
      <p>${product.price}</p>
      <p>{product.category}</p>
      <p>Rating: {product.rating}</p>
    </article>
  );
}

Now the same component can display completely different products.

Multiple Object Props

A component can receive more than one object prop.

For example:

function Dashboard({ user, course }) {
  return (
    <div>
      <h2>{user.name}</h2>
      <h3>{course.title}</h3>
    </div>
  );
}

The parent can provide both objects:

function App() {
  const user = {
    name: "Karimulla",
    role: "Frontend Developer"
  };

  const course = {
    title: "React",
    level: "Beginner"
  };

  return (
    <Dashboard
      user={user}
      course={course}
    />
  );
}

This can be useful when the component needs several related entities.

Objects vs Separate Props

Consider:

<User
  name="Karimulla"
  role="Frontend Developer"
  location="Hyderabad"
/>

versus:

<User
  user={{
    name: "Karimulla",
    role: "Frontend Developer",
    location: "Hyderabad"
  }}
/>

Both approaches can be appropriate.

Separate props make the component’s individual inputs very explicit.

An object prop can be convenient when the values naturally represent one entity and are already available together as an object.

For example, if an API returns:

const user = await fetchUser();

it may be natural to pass the returned user object:

<User user={user} />

The best choice depends on the component’s API and how the data is structured.

Objects from API Data

In real React applications, objects are commonly received from APIs.

Imagine an API returns:

{
  "id": 101,
  "title": "React Tutorial",
  "category": "React",
  "difficulty": "Beginner"
}

After receiving the data, you could pass the object to a component:

<TutorialCard tutorial={tutorial} />

The component can read its properties:

function TutorialCard({ tutorial }) {
  return (
    <article>
      <h2>{tutorial.title}</h2>
      <p>{tutorial.category}</p>
      <p>{tutorial.difficulty}</p>
    </article>
  );
}

This pattern is extremely common in production React applications.

Common Mistakes with Object Props

Forgetting Curly Braces

If user is a JavaScript object stored in a variable, pass it like this:

<User user={user} />

Not:

<User user="user" />

The second example passes the string "user" instead of the object stored in the variable.

Confusing the Prop with the Object Property

Suppose you have:

<User user={user} />

The child receives a prop named user.

You can access it using:

function User({ user }) {
  return <h2>{user.name}</h2>;
}

Here:

user → prop
user.name → property inside the object

Mutating an Object Prop

Don’t modify an object received through props directly.

Avoid:

function Profile({ user }) {
  user.name = "John";

  return <h2>{user.name}</h2>;
}

The child should treat props as read-only.

If the object represents state owned by the parent, the parent should handle the update.

Creating Unnecessarily Deep Objects

You don’t need to create deeply nested objects simply because React supports them.

Prefer a data structure that is easy for your application and components to understand.

Best Practices for Props with Objects

  • Use objects when multiple values naturally belong together.
  • Give object props descriptive names such as user, course, or product.
  • Destructure object props when it improves readability.
  • Avoid unnecessarily deep object structures.
  • Treat objects received through props as read-only.
  • If object data belongs to state, update it through the state setter.
  • Keep component APIs clear.
  • Pass only the data the component actually needs.
  • Use separate props when individual values make the component interface clearer.
  • Use an object prop when the values naturally represent one entity.
  • Be consistent with the data structure used throughout your application.

Web4Learners Practical Example

Imagine Web4Learners has a reusable tutorial card.

The tutorial data can be represented as an object:

const tutorial = {
  title: "Props with Objects",
  category: "React",
  difficulty: "Beginner",
  duration: "15 minutes",
  lessons: 8
};

Pass the object to the component:

<TutorialCard tutorial={tutorial} />

The reusable component reads the object:

function TutorialCard({ tutorial }) {
  return (
    <article className="tutorial-card">
      <span>{tutorial.category}</span>

      <h2>{tutorial.title}</h2>

      <p>
        Difficulty: {tutorial.difficulty}
      </p>

      <p>
        Duration: {tutorial.duration}
      </p>

      <p>
        Lessons: {tutorial.lessons}
      </p>
    </article>
  );
}

You can create another tutorial object:

const secondTutorial = {
  title: "Props with Arrays",
  category: "React",
  difficulty: "Beginner",
  duration: "12 minutes",
  lessons: 7
};

And reuse the same component:

<TutorialCard tutorial={tutorial} />

<TutorialCard tutorial={secondTutorial} />

The component doesn’t need to know which tutorial it is displaying.

It receives a tutorial object and uses its properties.

This is a practical example of combining objects, props, and reusable components.

Image Placement

Place the image immediately after the section “What Does Props with Objects Mean?”

Create a modern 16:9 Web4Learners-style React infographic showing an object being passed as a prop from a parent component to a child component. On the left, show:

const user = {
  name: "Karimulla",
  role: "Developer",
  location: "Hyderabad"
};

In the center, show:

<User user={user} />

On the right, show the child reading:

user.name
user.role
user.location

Use clear arrows to show the data flow. Keep the text minimal and use a polished modern React/developer aesthetic.

Caption: Passing a JavaScript object as a prop to a React component.

Alt text: React component receiving a user object as a prop and reading its properties.

Practice Exercise

Create a reusable StudentCard component.

Create a student object containing:

  • name
  • course
  • level
  • progress
  • completed

Start with:

function App() {
  const student = {
    name: "Karimulla",
    course: "React",
    level: "Beginner",
    progress: 80,
    completed: false
  };

  return <StudentCard student={student} />;
}

Create the StudentCard component.

Your component should:

  • Read the student object.
  • Display the student’s name.
  • Display the course.
  • Display the level.
  • Display the progress percentage.
  • Display "Course Completed" when completed is true.
  • Display "In Progress" when completed is false.
  • Create another student object and reuse the same component.

Then try destructuring the object’s properties inside the component.

Props with Objects Cheat Sheet

TaskExample
Create objectconst user = { name: "John" }
Pass object<User user={user} />
Read object propuser.name
Destructure propfunction User({ user })
Destructure objectconst { name } = user
Inline object<User user={{ name: "John" }} />
Nested propertyuser.address.city
Object in stateuseState({ name: "John" })
Update object statesetUser({ ...user, name: "Sam" })
Multiple object props<Dashboard user={user} course={course} />

Key Takeaways

  • React props can contain JavaScript objects.
  • Objects are useful for grouping related values.
  • An object can be passed as a single prop.
  • Use curly braces when passing an object stored in a JavaScript variable.
  • Object properties can be accessed with dot notation.
  • Object props can be destructured for cleaner code.
  • Objects can contain strings, numbers, booleans, arrays, and other objects.
  • Objects are commonly used when working with API data.
  • Object props should be treated as read-only by the receiving component.
  • Don’t mutate an object received through props.
  • When object data belongs to state, update it through the appropriate state setter.
  • Use object props when related values naturally represent one entity.
  • Use separate props when individual inputs make the component API clearer.
  • Understanding object props is important for working with real-world React data.

Leave a Comment