如果需要國家的顏色添加爲類名「奶酪」,那麼你可以不喜歡它
<button className={"cheese " + this.state.color}>
工作代碼
var Hello = React.createClass({
getInitialState: function(){
return {
color: 'blue'
};
},
handleClick: function(){
if (this.state.color === 'blue'){
this.setState({color: 'green'});
} else {
this.setState({color: 'blue'});
}
},
render: function() {
return <button className={"cheese " + this.state.color} onClick={this.handleClick}>My background is: {this.state.color}, Click me to change</button>;
}
});
React.render(<Hello name="World" />, document.getElementById('container'));
JSFIDDLE
[串聯變量的可能的複製和React中的字符串](http://stackoverflow.com/questions/39523040/concatenating-variables-and-strings-in-react) – Li357