Data-driven lists and class merging
Render repeated UI from data rather than duplicating markup. Use stable keys in React lists and keep each item's semantics clear. If a component accepts caller-provided classes, understand how conflicts are resolved: blindly appending p-8 after p-4 does not guarantee the expected result because generated CSS order is not simply the order of tokens in the HTML string.
A class-merging helper can resolve known Tailwind utility conflicts, but it is an additional dependency and must be compatible with your Tailwind version. It should not be used as a substitute for a coherent component API.
Data-driven cards
const metrics = [
{ label: "Open tasks", value: 18, tone: "text-blue-700" },
{ label: "Completed", value: 42, tone: "text-emerald-700" },
{ label: "Overdue", value: 3, tone: "text-red-700" },
];
function MetricGrid() {
return (
<section className="grid grid-cols-1 gap-4 sm:grid-cols-3">
{metrics.map((metric) => (
<article key={metric.label} className="rounded-xl border border-slate-200 bg-white p-5">
<p className="text-sm text-slate-600">{metric.label}</p>
<p className={`mt-2 text-3xl font-bold ${metric.tone}`}>{metric.value}</p>
</article>
))}
</section>
);
}đź’ˇ The array keeps content separate from presentation structure. Each item uses a stable key. The tone strings are complete utilities, and the grid responds to available width.
Key Takeaways
- Keep class candidates complete in source.
- Use stable keys for data-driven React lists.
- Define clear component APIs instead of relying on arbitrary class overrides.