I have two arrays which is an array of different animals and an array of name of animals. I want to make animal buttons and each animal buttons have its own color depending on what kind of animal they are.
I was using map functions but it didn't really worked.
export const animalColors = [
{
color: '#FF6800',
name: 'lion',
},
{
color: '#D80C18',
name: 'panda',
},
{
color: '#FF8A3D',
name: 'tiger',
},
{
color: '#02C75A',
name: 'rabbit',
},
{
color: '#608DF9',
name: 'bear',
},
{
color: '#0584F6',
name: 'elephant',
},
{
color: '#222F3E',
name: 'deer',
},
{
color: '#727272',
name: 'bird',
},
{
color: '#656598',
name: 'turtle',
},
];
const zoo = [
{ id: '1', name: 'lion' },
{ id: '2', name: 'panda' },
{ id: '3', name: 'tiger' },
{ id: '4', name: 'rabbit' },
{ id: '5', name: 'bear' },
{ id: '6', name: 'elephant' },
{ id: '7', name: 'deer' },
{ id: '8', name: 'bird' },
{ id: '9', name: 'turtle' },
]
These are the codes of typescript right below.
The data.docs is the array called zoo.
const BoardItemCard = ({ data }: BoardItemCardProps) => {
return (
<div className="BoardItemCard">
{data &&
data.docs.map((item: Item, i: number) => {
return (
<button style={{backgroundColor: ????}}>
{item.name}
</button>
)