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

Named Children vs Generic Children

Using specific component names (Tabs.List, Tabs.Panel) instead of accepting arbitrary children prop.

Named Children vs Generic Children

What you'll learn: How to use specific component names like Tabs.List and Tabs.Panel instead of accepting any arbitrary children prop in compound components.

The Problem with Generic Children

When you build compound components, you could accept a generic children prop and let users pass anything:

<Tabs>
  <div>Random div</div>
  <span>Random span</span>
  <SomeOtherComponent />
</Tabs>

This works, but you lose control and clarity. Which child is the tab list? Which are panels? You'd need to inspect each child's type or props to figure it out.

The Named Children Approach

Instead, use named sub-components that make the structure explicit:

<Tabs>
  <Tabs.List>
    <Tabs.Tab>Profile</Tabs.Tab>
    <Tabs.Tab>Settings</Tabs.Tab>
  </Tabs.List>
  <Tabs.Panel>Profile content here</Tabs.Panel>
  <Tabs.Panel>Settings content here</Tabs.Panel>
</Tabs>

Now the structure is self-documenting. You know exactly what each piece does.

Why This Matters

Analogy: Think of generic children like a box labeled "stuff" — you have to open it to know what's inside. Named children are like labeled drawers — "socks," "shirts," "pants" — you know immediately where everything belongs.

Named children give you:

  • Type safety (TypeScript knows what props each sub-component accepts)
  • Clear intent (developers reading your code understand the structure)
  • Easier implementation (no need to inspect or filter children)
  • Better error messages (you can validate that Tabs.List was actually used)

Key Takeaway: Named children (like Tabs.List, Tabs.Panel) create self-documenting, type-safe compound components instead of accepting generic, ambiguous children props.