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

What Slots Are: Named Placeholders for Content

Understand slots as a pattern for explicitly defining where child content should render within a component.

What Slots Are: Named Placeholders for Content

You'll learn: How slots provide an explicit, named way to define exactly where different pieces of content should appear inside a component.

The Core Idea

Think of a slot like a labeled socket in a wall. Instead of having one generic "children" hole where everything gets plugged in, slots give you multiple named sockets: "header goes here," "footer goes here," "sidebar goes here." Each slot is a deliberate placeholder that says "this specific type of content belongs in this exact spot."

In React, we've been using children to pass content into components, but children is vague—it's just "whatever you put between the tags." Slots take this further by letting you name specific areas of your component's layout and explicitly decide what renders in each area.

Why Named Placeholders Matter

When building complex layouts, you often need more control than a single children prop provides. A Card component might need separate areas for a title, an image, content, and actions. Rather than forcing users to wrap everything in specific child components or use a rigid structure, slots let them say "here's my title content" and "here's my action content"—and your component knows exactly where to place each piece.

This pattern makes component APIs more declarative and flexible. The parent component using your slot-based component can provide content in any order, and your internal layout logic decides the final rendering positions.

Key Takeaway: Slots are named placeholders that give you explicit control over where different pieces of content render, moving beyond the single-purpose children prop to support more complex, multi-area component layouts.