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

The Problem Slots Solve: Multiple Content Areas

Learn why the single children prop isn't enough when you need to render content in multiple distinct locations.

The Problem Slots Solve: Multiple Content Areas

You'll learn: Why passing content through the single children prop breaks down when a component needs to render content in multiple distinct locations.

The Limitation of children

When building compound components, you've learned to pass content through the children prop. This works beautifully for simple cases—a single content area that gets rendered in one place:

<Card>
  <p>All this content goes in one spot</p>
</Card>

But what happens when your component needs to render content in multiple distinct locations? Imagine a Dialog component that needs a title at the top, content in the middle, and actions at the bottom. Or a Panel with a header, body, and footer.

You can't split children into three pieces. It's just one prop.

The Awkward Alternatives

Without slots, you face messy workarounds:

  • Multiple props: <Dialog title={...} content={...} actions={...} /> — but now you're passing JSX through many props, which feels unnatural
  • Array children with conventions: <Dialog>{[title, content, actions]}</Dialog> — fragile and requires documentation
  • Wrapper components: <DialogTitle>, <DialogContent>, etc. — works, but requires context setup and validation

What Slots Provide

Slots give you named placeholders where different pieces of content can be rendered independently. Instead of forcing everything through one children pipe or creating awkward prop APIs, slots let you say "this content goes here, that content goes there" declaratively.

Think of slots like a mail-sorting system: the single children prop is one big mailbox, while slots give you separate, labeled cubbies for different types of content.

Key Takeaway: The children prop is too limited when components need to render content in multiple distinct areas—slots solve this by providing named, independent content placeholders.