React has no class hierarchy you extend. You build complex UIs by nesting components inside components and passing pieces of UI as props or children. That's composition. It scales further than any class tree.
Two composition idioms
Almost all React composition reduces to two patterns:
- The
childrenprop — the parent renders a frame and lets children fill the inside. - Slot props — named props (other than
children) that take React nodes, letting a parent compose into specific positions.
You'll see slot-prop layouts (header / body / footer) in dashboards, dialogs, and cards. The children prop alone covers the simple case; slot props win when there are multiple distinct positions.
The compound component pattern
Sometimes you want callers to write <Tabs><Tab>A</Tab><Tab>B</Tab></Tabs>. The Tabs parent owns the active state, and Tab children read it from context. This is compound components — parent and children share an implicit state contract. Use sparingly; great for libraries, can be over-engineered for app code.
The asChild / Slot pattern
A pattern Radix UI popularized: instead of cloning a styled <button> into a <Link>, you let callers pass asChild and the component renders its children as the actual element, merging in its own behavior. Lets the same Button become a real anchor when wrapped around a <Link>.