Start With the Obvious Wrapper
A minimal React Card component looks like this:
const Card = props => {
return(
<div className="card">
<h2>{props.title}</h2>
<p>{props.content}</p>
</div>
)
}
Used hundreds of times, it buys you a small piece of HTML refactoring leverage. CSS class names already gave you style control; now you get HTML control as well.
Questioning the Assumptions
The hardcoded <h2> is the first thing to fall. Some usages may genuinely need an <h4>. One option is an API of sorts:
const Card = props => {
return(
<div className="card">
{props.type === "big" && <h2>{props.title}</h2>}
{props.type !== "big" && <h4>{props.title}</h4>}
<p>{props.content}</p>
</div>
)
}
Another is to force the caller to pass a level in:
const Card = props => {
const HeaderTag = `h${props.level}`;
return(
<div className="card">
<HeaderTag>{props.title}</HeaderTag>
<p>{props.content}</p>
</div>
)
}
A third is to make the header its own component.
The forced paragraph wrapper around the content is similarly limiting. A <div> would accept arbitrary HTML, such as multiple paragraphs:
const Card = props => {
return(
<div className="card">
<WhateverHeader>{props.title}</WhateverHeader>
<div>{props.content}</div>
</div>
)
}
Then there is the question of why content is supplied via props at all. Children are usually easier to work with, especially when the payload is HTML:
const Card = props => {
return(
<div className="card">
<WhateverHeader>{props.title}</WhateverHeader>
{children}
</div>
)
}
The Class Name and the Wrapper Tag
More assumptions can be challenged, starting with the card class name itself:
const Card = props => {
const classes = `card ${props.className}`;
return(
<div className={classes}>
<WhateverHeader>{props.title}</WhateverHeader>
{children}
</div>
)
}
Yet this still hardcodes card. The component could drop that assumption, or expose a way to opt out of it. The <div> wrapper is just as presumptuous — the tag name could be passed in, so the same component becomes a <section>, an <article>, or anything else.
Assuming nothing at all yields this:
const Card = () => {
return(
<>
{children}
</>
)
}
Anything a caller wants to change, they can change. The result is relaxed flexibility rather than the defensive kind:
<Card
parentTag="article"
headerLevel="3"
headerTitle="My Card"
contentWrapper="div"
cardVariation="extra-large"
contentContent=""
this=""
little=""
piggy=""
went=""
to=""
market=""
/>
That extreme-API-zying tends to appear when control and flexibility are pursued at the same time.
Over-Componentization and the Balance
A component model with no guidance can also push toward over-componentization:
const Card = props => {
return(
<CardWrapperTheme>
<CardWrapper>
<CardTitle />
<CardContent />
<CardFooter />
</CardWrapper>
</CardWrapperTheme>
)
}
There may be good reasons for splitting things this finely, or it may simply be componentizing because it is “free” and because that is how things are done in an architecture that supports it.
The balance is the interesting part. A component that is too strict risks going unused because it does not give people what they need. A component that is too loose risks going unused because it provides no value — and, even where it is used, no cohesiveness.



