Course contentsShow
← React
Lesson 1129 of 2,39629. Composition: SlotsFree lesson

The Named Children Problem

Understanding why passing multiple distinct pieces of content to a component requires more than just the children prop.

The Named Children Problem

You'll learn why the children prop alone can't handle complex component layouts that need multiple distinct content areas.

The Core Issue

Imagine building a Card component that needs a header, body, and footer — three separate content areas. The children prop gives you one "slot" for generic content, but it doesn't distinguish between these three areas.

If you try something like this:

<Card>
  <div>Header content</div>
  <div>Body content</div>
  <div>Footer content</div>
</Card>

Inside Card, all three divs arrive as children — just a flat list. You have no way to know which is which. You could rely on order (first child = header, second = body, etc.), but that's fragile and unclear to anyone reading your code.

Why This Matters

Real-world components often need multiple named areas:

  • A dialog with header, content, and actions
  • A layout with sidebar, main, and toolbar
  • A table with custom header and footer sections

Using children for all of them forces you into awkward workarounds: wrapping everything in a single container, relying on array positions, or complex child type-checking logic.

The "Named Children Problem" is recognizing that children is singular by design — it's one blob of content. When your component API needs to distinguish between multiple content areas, you need a different approach (like explicit slot props or compound components).

Key Takeaway: The children prop works for single content areas, but components needing multiple distinct regions require named slots or composition patterns to keep the API clear and type-safe.