My goal here is to have a box that renders the word of a color in order within the array.
I'm struggling with the concept on rendering each element of the array. I'm assuming you'd need to pick out each element, store it in a variable, and render the variable but I'm hitting a dead end each time I attempt it.
You'll see my commented out attempt in the code below. I also tried forEach but React gave me an error while trying to use forEach.
Additionally, I was told to avoid using .map and a for loop if possible.
import React from 'react'
class ColorSwitch extends React.Component {
constructor(props) {
super(props)
this.state = {
colors: ["white", "orange", "purple", "black", "green"]
}
}
nextColor = () => {
let newColor = this.state.colors
// let setColor = newColor[0] += 1 (DIDNT WORK)
this.setState({colors: setColor})
}
render() {
let { colors } = this.state
return(
<div className="box" onClick={this.nextColor}>
<p>{this.setColor}</p>
</div>
)
}
}
export default ColorSwitch
Thanks in advance for your help.
let setColor = newColor[0] + 1?