Instead of filtering the data array inside <Summary>
, you could iterate over the array in <Home>
, like this:
<h3 className="text-lg text-black pb-4">Summary</h3>;
{
data.scores.map((score) => {
return <Summary key={score.category} {...score} />;
});
}
The colors could be stored in an object with the category as a key:
const colorsByCategory = {
Reaction: {
bgColor: "bg-red-100",
textColor: "text-red-600",
},
/* ... */
};
Or, you could style the items using data modifiers:
<div
className="data-[category=Reaction]:bg-red-100 data-[category=Reaction]:text-red-600 ..."
data-category={category}
>
Marked as helpful
@FLuffy-teddy
Posted
@markuslewin
Thanks for the response, actually very useful for this next project I am tackling.