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

When Slots Win: Multiple Named Insertions

Discover how slots excel when you need multiple, distinct insertion points (header, footer, sidebar) without the mental overhead of render props.

When Slots Win: Multiple Named Insertions

You'll learn: When passing JSX as named props (slots) becomes the clearest choice for components with multiple distinct content areas.

The Sweet Spot for Slots

Slots shine brightest when your component needs multiple, clearly labeled insertion points — and you want to keep the API simple and obvious.

Imagine building a Panel component with three distinct areas: a header, main content, and footer. Using children alone forces you into weird workarounds (array indexing, string markers, compound components). Using render props works but adds mental overhead — you're passing functions just to return JSX.

Slots cut through this complexity: just pass JSX elements as named props.

The Three-Slot Scenario

<Panel
  header={<h2>Dashboard</h2>}
  footer={<button>Save</button>}
>
  <p>Main content goes here</p>
</Panel>

Each insertion point has a clear name. No nested structure to remember. No context setup required. The component receives three pieces of JSX and places them exactly where they belong.

Compare this to a render prop version:

<Panel
  renderHeader={() => <h2>Dashboard</h2>}
  renderFooter={() => <button>Save</button>}
>
  {() => <p>Main content</p>}
</Panel>

Same result, but now you're wrapping everything in functions for no actual benefit — there's no dynamic logic, no arguments being passed. Pure ceremony.

When Slots Are the Right Choice

  • Multiple named areas (header, sidebar, footer, toolbar)
  • Static content (just JSX, not computed values)
  • Parallel placement (not hierarchical nesting)
  • Simple APIs where users shouldn't think about functions

Key Takeaway: Slots win when you need multiple, clearly named content areas without the complexity of render props or compound components — just straightforward JSX-as-props composition.