Component Composition Over Configuration

Stop building "God Components" with 30 props. Sometimes the best API is no API at all. Let's explore why composition beats configuration for maintainable React systems.
We've all seen them: the "God Components." A single <Button /> or <Card /> with 20+ props, half of them optional, creating a configuration nightmare. You start with title, then add hasIcon, then iconPosition, then isLoading... before you know it, youβre debugging a labyrinth of if/else statements inside your JSX.
The "Prop Soup" Problem
Every new prop you add to a component increases its complexity exponentially:
π Combinatorial Explosion: 10 boolean props mean 1,024 possible states to test.
π Leaky Abstractions: Your component starts caring about things it shouldn't.
π Rigidity: Want to add a sub-title? Now you need a
subTitleprop and asubTitleStyleprop.
The Solution: Atomic Composition
Instead of trying to predict every future use case with props, give the power back to the developer using the component.
β The Configuration Nightmare (Rigid)
TypeScript
<Card
title="Project Alpha"
showIcon={true}
footerText="Active"
variant="dark"
/>
β The Composition Dream (Flexible)
TypeScript
<Card variant="dark">
<Card.Header>
<Icon name="zap" />
<h2>Project Alpha</h2>
</Card.Header>
<Card.Body>...</Card.Body>
<Card.Footer>
<Badge status="active" />
</Card.Footer>
</Card>
Why Composition Wins
Inversion of Control: The consumer decides the structure, not the component author.
Reduced Surface Area: Your base component only manages state/logic; the layout is handled by the children.
No More "Prop Drilling": You don't need to pass a
titleClassNamethrough 3 layers just to change a font size.
When to Still Use Props
Props are for state and identity, not for structure.
π Use Props for:
size,color,isDisabled,onClick.π Use Composition for: Layout, nesting, and complex internal structures.
Conclusion
Think of your components as LEGO bricks, not as pre-built machines. A machine has limited settings; bricks can become anything. Build bricks.


