Course contentsShow
← React
Lesson 1112 of 2,39628. Composition: Compound ComponentsFree lesson

Creating Named Child Components

Build individual child components (e.g., Tabs.List, Tabs.Trigger, Tabs.Panel) that consume the internal context.

Creating Named Child Components

You'll learn how to define the individual child pieces (like Tabs.List, Tabs.Trigger, Tabs.Panel) that consume your compound component's internal context.

What Are Named Child Components?

Named child components are the puzzle pieces that users compose together. They're attached to the parent component using dot notation (e.g., Tabs.List) and internally consume the shared context you created. Each child has a specific responsibility and communicates with the parent through that private context—no props drilling required.

Think of it like a restaurant: the parent component is the kitchen, the context is the order system, and the named children are the stations (grill, salad prep, dessert). Each station knows what to do by checking the order system, but customers (developers using your API) just see clean, composable pieces.

Building Your Named Children

Each child component:

  1. Consumes the context using your custom hook (the one that enforces context usage)
  2. Reads state or actions it needs from that context
  3. Renders its specific UI based on that shared state

For a Tabs component, you might create:

  • Tabs.List – consumes context to know if it should wrap triggers
  • Tabs.Trigger – consumes context to get the active tab and trigger change events
  • Tabs.Panel – consumes context to determine if it should display

Each child is a standalone component function, but they all rely on being descendants of the parent (which provides the context). You attach them to the parent object using simple property assignment: Tabs.List = TabsList.

Why This Works

Users compose your components freely, mixing and matching as needed, while you guarantee consistent state management underneath. The named children remain simple—they just consume context—while the parent handles all coordination.

Key Takeaway: Named child components are focused, context-consuming pieces attached to the parent via dot notation, giving users composable APIs without prop complexity.