Receiving Children in Components
What you'll learn: How to use destructuring to access the children prop and render nested content inside your custom components.
The Core Pattern
You've learned that children is a special prop React automatically provides when content is placed between component tags. Now it's time to actually receive and use it.
Just like any other prop, children arrives in your component's props object. You can destructure it alongside other props:
function Card({ title, children }) {
return (
<div className="card">
<h2>{title}</h2>
<div className="card-body">
{children}
</div>
</div>
);
}
// Usage:
<Card title="Welcome">
<p>This text becomes the children prop!</p>
<button>Click me</button>
</Card>
How It Works
When you destructure { children } in the function parameter, you're pulling out that special prop. Then you place {children} in your JSX wherever you want the nested content to appear.
Think of it like a slot machine: your component defines the frame and structure, but children is the slot where the parent component can inject custom content.
Without Destructuring
You can also access children through the full props object:
function Box(props) {
return <div className="box">{props.children}</div>;
}
Both approaches work identically—destructuring is just cleaner when you need children frequently.
Key Takeaway: Destructure children from props like any other prop, then render it with {children} wherever you want the nested content to appear in your component's structure.