Multiple Named Content Props
What you'll learn: How to design a component that accepts several JSX props—like header, footer, and sidebar—allowing consumers to provide distinct content pieces for different layout regions.
The Core Idea
You've already learned that JSX elements can be passed as regular props. Now we're applying that pattern at scale: instead of just one content prop, you accept multiple named props, each representing a specific section of your component's layout.
Think of it like a form with multiple fields. Instead of one giant text box, you have separate inputs for "name," "email," and "phone." Similarly, a layout component might need distinct content for different regions—and named props make this explicit and discoverable.
How It Works
interface LayoutProps {
header: React.ReactNode;
sidebar: React.ReactNode;
footer: React.ReactNode;
children: React.ReactNode;
}
function Layout({ header, sidebar, footer, children }: LayoutProps) {
return (
<div className="layout">
<header>{header}</header>
<div className="content">
<aside>{sidebar}</aside>
<main>{children}</main>
</div>
<footer>{footer}</footer>
</div>
);
}
// Usage
<Layout
header={<h1>My App</h1>}
sidebar={<Navigation />}
footer={<Copyright />}
>
<p>Main content goes here</p>
</Layout>
Each prop has a clear, semantic name. The consumer knows exactly where their content will appear. No guessing, no digging through documentation.
Why This Matters
- Clarity:
sidebar={...}is more explicit than nested children - Type Safety: Each slot has its own type definition
- Flexibility: Consumers control all regions independently
- Discoverability: IDE autocomplete shows all available slots
Key Takeaway: Multiple named content props turn your component into a multi-region layout system where each content area is explicitly named, typed, and independently controllable—perfect for complex layouts with distinct sections.