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

Three Ways to Inject Content: A Comparison

Understand slots (named props), children (special prop), and render props (functions) as three fundamental patterns for composing React components.

Three Ways to Inject Content: A Comparison

What you'll learn: How slots (named props), children (special prop), and render props (functions) compare as three fundamental patterns for composing React components.

The Three Patterns Side by Side

You've now learned three powerful ways to let parent components customize what child components display. Think of these as three different doors for content to enter a component:

Slots (Named Props): You pass JSX elements as explicitly named props like header={<Logo />} or footer={<Nav />}. Best when you have multiple, clearly-defined content areas that you want to name.

<Card 
  header={<h2>Title</h2>}
  body={<p>Content</p>}
  footer={<Button />}
/>

Children Prop: You pass content between opening and closing tags. Perfect for single content areas or when the component wraps content naturally.

<Card>
  <h2>Title</h2>
  <p>Content</p>
</Card>

Render Props: You pass functions that return JSX, often receiving data or callbacks as arguments. Ideal when the parent needs access to the child's internal state or logic.

<DataProvider>
  {(data, loading) => (
    loading ? <Spinner /> : <Display data={data} />
  )}
</DataProvider>

Choosing the Right Pattern

  • Use slots when you need multiple named areas and clear structure
  • Use children for simple wrapping or single content injection
  • Use render props when you need to share state/logic upward

Each pattern has its place. Slots are explicit and predictable. Children feel natural and clean. Render props unlock dynamic behavior. You're not locked into one—many components combine these patterns!

Key Takeaway: Slots (named props) offer structure, children offer simplicity, and render props offer dynamic control—choose based on whether you need multiple areas, simple wrapping, or state sharing.