Reputation: 7153
This code actually works in my environment, and I'm actually trying to create a fiddle to ask a different question but need to solve this first...
Why is the console saying that 'favorited' is not defined?
class BtnFav extends React.Component {
constructor(props) {
super(props);
this.state = {favorited: false};
this.handleClick = this.handleClick.bind(this);
}
handleClick() {
this.setState({favorited: !this.state.favorited});
}
render() {
var favStatus = this.state.favorited ? 'btn-fav' : 'btn-notfav';
return (
<button className={favStatus} onClick={this.handleClick}>FAVORITE</button>
);
}
};
Upvotes: 0
Views: 47
Reputation: 1218
The only error I was able to find was a misspelling of 'background'. In your original example you've specified:
.btn-fav {
backround-color: green;
}
.btn-notfav {
backround: red;
}
The property is correctly spelled as background
or background-color
See this updated example: https://jsfiddle.net/69z2wepo/49511/
Upvotes: 1