I've been working on some JavaScript code that pulls a random color from a selection:
const colors = [blue[800], green[500], orange[500], purple[800], red[800]];
const color = colors[Math.floor(Math.random() * colors.length)];
Within my JSX code, I display an image with a randomly chosen color
{this.state.data.map((n, i) => {
return (
<Avatar style={{backgroundColor: color}}>{n.author.charAt(0).toUpperCase()}</Avatar>
);
})}
The trouble I'm running into is that every item displayed ends up being the same random color, like orange. My goal is to have each item show up in a unique color, but I'm unsure how to make this happen.