In my react application the background-color for some child elements is given through props from state. Initial value for all colors is null, so the elements are just transparent. After some interaction and clicking user can change the state values to some other colors so the background changes.
After that I want to be able to set all colors back to null but somehow it doesn't work, here is a small part of my code:
state = { colors: [
{ id: 1, color: null },
{ id: 2, color: null },
{ id: 3, color: null },
{ id: 4, color: null }
]}
reset = () => {
let colors = [...this.state.colors]
colors.forEach(color => color.color = null)
this.setState({ colors: colors })
}
The values of the color keys in the state change back to null as expected, but the colors of the elements don't disappear. If I try to do something like
colors.forEach(color => color.color = "red")
then all the colors actually do change to red, but why can't I get the same result with null?