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

Advantages Over Monolithic Components

How compound components provide more flexibility than single components with many props.

Advantages Over Monolithic Components

You'll learn how compound components provide more flexibility than single components with many props.

The Monolithic Component Problem

Imagine a traditional Menu component that tries to handle everything through props:

<Menu
  triggerLabel="Options"
  triggerIcon="⋮"
  showDivider
  items={[
    { label: 'Edit', onClick: handleEdit },
    { label: 'Delete', onClick: handleDelete, danger: true }
  ]}
  closeOnSelect
  placement="bottom"
/>

This works, but it's rigid. Every customization requires a new prop. Want a custom trigger? New prop. Need an icon in a menu item? Extend the item shape. The API surface grows exponentially.

Compound Components: Flexibility by Design

With compound components, you compose the same functionality with actual components:

<Menu>
  <Menu.Trigger>
    <button>⋮ Options</button>
  </Menu.Trigger>
  <Menu.Items>
    <Menu.Item onSelect={handleEdit}>Edit</Menu.Item>
    <Menu.Divider />
    <Menu.Item onSelect={handleDelete} className="danger">
      Delete
    </Menu.Item>
  </Menu.Items>
</Menu>

Why This Wins

Customization without permission: You don't need the library author to add a customTrigger prop—just put whatever you want inside Menu.Trigger.

Natural composition: Adding icons, badges, or complex layouts inside menu items becomes trivial—they're just children.

Fewer props, clearer intent: Instead of memorizing 20 props, you compose familiar building blocks.

Progressive enhancement: The component can start simple and grow complex only where needed.

Think of it like LEGO versus a pre-built toy. Monolithic components are pre-built: functional but fixed. Compound components are LEGO blocks: more pieces to learn, but infinite flexibility.

Key Takeaway: Compound components trade a larger API surface (more component names) for dramatically increased flexibility and composability, eliminating the need for an ever-growing props list.