I have a list of categories coming form an API call:
Diagnosis
Client Statements
Damages
I need to assign an icon on the frontend to each of the categories received and I thought the best way to do this was to map the categories using a switch statement.
let icon = '';
const handleIcon = () => {
categories.map((cat) => {
switch (cat.categoryName) {
case 'Diagnosis':
icon = 'checklist-24';
break;
case 'Client Statements':
icon = 'document-24';
break;
case 'Damages':
icon = 'car-crash-24'
break;
default:
break;
}
});
};
My problem is that all the categories end up being the last icon because they are all true in the end for my map function.
categories.map((cat) => {
<div>{icon}</div>
<div>{cat.categoryName}</div>
})
How can I assign a different icon according to the name of the category in my map?
Thanks.