Course contentsShow
← React
Lesson 196 of 2,3966. Component BasicsFree lesson

Component Composition vs Prop Explosion

When composition provides a cleaner solution than adding endless props to a single component.

Component Composition vs Prop Explosion

You'll learn when breaking components apart is cleaner than adding endless props to a single component.

The Problem: Prop Explosion

As components grow, they often accumulate more and more props. You start with a simple Card component, then add props for title styling, body padding, header background, footer alignment, and suddenly you have:

<Card 
  titleColor="blue"
  titleSize="large"
  bodyPadding="md"
  headerBg="gray"
  footerAlign="right"
  showBorder={true}
  shadowSize="sm"
/>

This is prop explosion — when a component becomes a Swiss Army knife of configuration options. It's hard to use, hard to maintain, and hard to understand.

The Solution: Composition

Instead of configuring everything through props, compose smaller, focused components:

<Card>
  <CardHeader style={{backgroundColor: 'gray'}}>
    <h2 style={{color: 'blue', fontSize: '24px'}}>Title</h2>
  </CardHeader>
  <CardBody style={{padding: '16px'}}>
    Content here
  </CardBody>
  <CardFooter style={{textAlign: 'right'}}>
    Footer content
  </CardFooter>
</Card>

Now each piece is explicit and flexible. Want a different header? Just compose it differently. No new props needed.

When to Choose Composition

Think of it like LEGO blocks versus a single customizable piece. Would you rather have one complex block with 20 adjustment knobs, or several simple blocks you can arrange however you want?

Choose composition when:

  • You're adding props just to pass styling deeper
  • Your component has 5+ configuration props
  • Different use cases need different internal structures

Key Takeaway: When you're adding your fifth prop for customization, step back and ask if composition — breaking the component into smaller, composable pieces — would be cleaner than creating a mega-component with endless configuration options.