Slots vs Children: When Each Fits
You'll learn when to use simple children versus explicit slot props for cleaner, more maintainable component APIs.
The Core Distinction
React's children prop works beautifully when you have a single content area that gets inserted in one place. But when your component needs multiple, named regions for content (header, footer, sidebar, actions), explicit slot props make your intent crystal clear.
Think of children like a single pocket in a jacket — perfect for one thing. Slots are like a backpack with labeled compartments: "laptop here, water bottle here, books here." Both carry stuff, but one is organized for complexity.
When Children Fits
Use children when:
- You have one insertion point for content
- The component's structure is simple and obvious
- Users expect standard "wrapper" behavior
<Card>
<p>All content goes here, in order</p>
</Card>
When Slots Fit Better
Use explicit slot props when:
- You have multiple named regions with different purposes
- Content areas aren't adjacent or sequential
- You want to make the API self-documenting
<Modal
header={<h2>Confirm Action</h2>}
footer={<Button>OK</Button>}
>
<p>Main content</p>
</Modal>
The slot approach makes it immediately obvious where each piece goes. A new developer doesn't need to guess or read docs — the prop names tell the story.
The Readability Test
If someone reading your component can't tell where content will appear just by looking at the JSX, slots win. If the flow is obvious, children is simpler.
Key Takeaway: Use children for single-area composition; use named slot props when multiple distinct regions need explicit, self-documenting placement.