How do you add a CSS class to an existing REACT element on click?
I have a JSFiddle created: https://jsfiddle.net/5r25psub/
In the fiddle, the code only wor
You need to add all state parameters to getInitialState, right now the only thing you have is color, so this.state.color is the only thing in there
When you set your state to className: something, that is the only thing in there now, even color is gone...and that is why the initial color is the normal bland gray
you have a syntax error in setState as well, its not
this.setState({className = " green"});
It should be:
this.setState({className: " green"});
Finally, React.render is deprecated, you need to use ReactDOM.render now
Fiddle: https://jsfiddle.net/omarjmh/69z2wepo/36597/