Skip to content

Instantly share code, notes, and snippets.

@mariodev12
Created September 15, 2016 17:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariodev12/40521fb6cd9a6d02bd0e842a4e669fac to your computer and use it in GitHub Desktop.
Save mariodev12/40521fb6cd9a6d02bd0e842a4e669fac to your computer and use it in GitHub Desktop.
import React, {Component} from 'react';
class HeartButton extends Component {
constructor(props) {
super(props);
this.state = {active: false};
}
handleClick(){
this.setState({
active: !this.state.active
})
}
render(){
let heart = this.state.active ? 'fa fa-heart heart-red' : 'fa fa-heart-o';
return (
<span className="heartIcon" onClick={this.handleClick.bind(this)}>
<i className={heart}></i>
</span>
)
}
}
export default HeartButton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment