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

Slots vs Compound Components: Design Tradeoffs

Compare explicit slot props with compound components to choose the right composition pattern for your use case.

Slots vs Compound Components: Design Tradeoffs

You'll learn how to decide between explicit slot props and compound components for your component APIs.

The Core Decision

Both slots (named props) and compound components solve the same fundamental problem: allowing flexible composition of multiple content areas. But they approach it differently, and each has clear strengths.

Slots pass content through explicit props like header={<...>} and footer={<...>}. Compound components use a parent-child relationship where children communicate through shared context.

When to Choose Slots

Use slots when:

  • You have a fixed layout with known content areas
  • The parent needs to control positioning of each piece
  • You want simple, explicit APIs that are easy to discover
  • TypeScript types need to be clear and autocomplete-friendly
  • The number of content areas is small and stable
<Card 
  header={<Title />}
  body={<Content />}
  footer={<Actions />}
/>

When to Choose Compound Components

Use compound components when:

  • Children need flexible ordering decided by the consumer
  • You have many optional pieces that would clutter the prop list
  • Components need to share state (active tab, selected item)
  • You want a fluent, declarative API
  • The pattern mirrors real-world composition (tabs, menus, accordions)
<Tabs>
  <Tabs.List>
    <Tabs.Tab>One</Tabs.Tab>
    <Tabs.Tab>Two</Tabs.Tab>
  </Tabs.List>
  <Tabs.Panel>Content 1</Tabs.Panel>
  <Tabs.Panel>Content 2</Tabs.Panel>
</Tabs>

Key Takeaway: Choose slots for simple, structured layouts with fixed positions. Choose compound components when you need state sharing, flexible ordering, or many optional pieces that work together as a cohesive unit.