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

Basic Slot Pattern: Multiple Props for Content

Implement the simplest slot pattern by accepting JSX as named props like header, footer, and sidebar.

Basic Slot Pattern: Multiple Props for Content

You'll learn how to create flexible layouts by accepting JSX elements as separate named props, giving your components multiple "slots" for different content areas.

The Core Idea

Instead of passing all JSX through a single children prop, you can accept multiple named props that each receive their own piece of JSX content. Think of it like a webpage template with distinct zones: a header area, a sidebar area, and a footer area. Each zone is a "slot" that accepts whatever content the parent wants to place there.

This is the simplest form of the slot pattern—no context, no magic, just props that happen to contain JSX.

How It Works

You define props like header, sidebar, or footer in your component. The parent passes JSX elements to these props just like any other prop:

function PageLayout({ header, sidebar, footer, children }) {
  return (
    <div className="layout">
      <div className="header">{header}</div>
      <div className="main">
        <aside className="sidebar">{sidebar}</aside>
        <main className="content">{children}</main>
      </div>
      <div className="footer">{footer}</div>
    </div>
  );
}

// Usage
<PageLayout
  header={<h1>My App</h1>}
  sidebar={<nav>Navigation here</nav>}
  footer={<p>© 2024</p>}
>
  <p>Main content goes here</p>
</PageLayout>

Each prop acts as a labeled container where specific UI lives. The component controls where each slot renders, while the parent controls what fills each slot.

Why This Pattern Works

Unlike a single children prop, named slots make the component's structure explicit. You know exactly where your header will appear versus your footer—no guessing about layout order.

Key Takeaway: The basic slot pattern uses ordinary props that accept JSX, giving you multiple named content areas without any complex machinery—just props, JSX, and clear composition.