I'm use functional component of reactjs. I have an array of objects in which the styles are specified
const data = [
{
id: 1,
color: '#000'
},
{
id: 2,
color: '#fff'
}
// etc
]
I need to render as many elements on the page as there are objects in the data array, and each element gets its own unique color (the first element gets color from the first object, the second from the second, etc.).
For this I use the custom hook useStyles from material-ui.
const useStyles = makeStyles((theme) => ({
divColor: {
background: data.map((el) => (
el.color
)
)
}
}));
I expand the HTML part itself like this
{data.map((el, index) => <div key={index} className={classes.divColor} />)}
In this case, I have 2 identical div elements, with the same property
.makeStyles-startAccident-4 {
background: #000, #fff;
}
Where did I go wrong?