When you’re learning React, one of the first things you’ll notice is this kind of syntax:
function Welcome({ name }) {
return <h1>Hello {name}</h1>;
}
It might look unusual at first, but this is simply object destructuring — a JavaScript feature that React uses very heavily to make working with props easier.
📌 Note:
If you’re not familiar with object destructuring in JavaScript itself, you may want to check out the earlier post Understanding Object Destructuring in JavaScript.
Now, let’s understand how destructuring works specifically inside React components.
⭐ What Does React Normally Do With Props?
React components always receive props as a single combined object.
For example:
function Welcome(props) {
return <h1>Hello {props.name}</h1>;
}
Here, props looks like this:
props = {
name: "Heartin",
age: 16
};
⭐ What Does Destructuring Do?
Object destructuring lets us pull out only the values we want:
function Welcome({ name }) {
return <h1>Hello {name}</h1>;
}
This means:
“Extract the
nameproperty from the props object.”
It’s still JavaScript — React does not add any special behavior.
⭐ Why Destructuring Is So Common in React
You will see destructuring everywhere in React because:
✔ It makes our code shorter
Instead of props.name, we simply write name.
✔ It makes components easier to understand
We can see exactly which props the component needs.
✔ It keeps code cleaner
No more repeating the word props.
⭐ Two Ways to Use Destructuring in React
✔ 1. Destructuring directly in the function parameters (most common)
function Profile({ name, age }) {
return <p>{name} is {age} years old</p>;
}
This is the cleanest and most popular pattern.
✔ 2. Destructuring inside the component body
function Profile(props) {
const { name, age } = props;
return <p>{name} is {age} years old</p>;
}
Useful when:
- debugging props
- applying conditional logic
- handling dynamic props
Both are equally valid.
⭐ Default Values With Destructuring
You can assign default values when destructuring props:
function Welcome({ name = "Guest" }) {
return <h1>Hello {name}</h1>;
}
If no name prop arrives, “Guest” is used automatically.
⭐ Nested Prop Destructuring
Some props contain nested objects:
function User({ info: { username, email } }) {
return <p>{username} - {email}</p>;
}
This works when props look like this:
props = {
info: {
username: "heartin",
email: "example@gmail.com"
}
};
⭐ Destructuring Props in TypeScript
Destructuring works exactly the same in TypeScript — just add types.
type UserProps = {
name: string;
age: number;
};
function User({ name, age }: UserProps) {
return <p>{name} is {age} years old</p>;
}
⭐ Bonus: Destructuring children
React components often receive children, which can also be destructured:
function Card({ title, children }) {
return (
<div>
<h2>{title}</h2>
{children}
</div>
);
}
Great for reusable UI components. Read more at Understanding the Special children Prop in React.
⭐ Quick Summary
| Topic | Why it matters |
|---|---|
| Destructuring props | Makes components cleaner and easier to read |
| Default values | Prevents missing-prop errors |
| Nested destructuring | Helps extract structured data |
| Works the same in TypeScript | Yes, with added type safety |
| Common in React | Because props are always objects |
🎉 Final Thoughts
Object destructuring isn’t a React feature — it’s a JavaScript feature that fits beautifully with how React components receive props.
Once you understand destructuring, React becomes far more intuitive and your components become easier to read and maintain.