Skip to content

Instantly share code, notes, and snippets.

@JacobHsu
Created October 17, 2016 02:14
Show Gist options
  • Save JacobHsu/19847b5c1a4dad8f6ace6d786975918b to your computer and use it in GitHub Desktop.
Save JacobHsu/19847b5c1a4dad8f6ace6d786975918b to your computer and use it in GitHub Desktop.
Hello World React
<div id="example"></div>
var LikeButton = React.createClass({
getInitialState: function() {
return {liked: false};
},
handleClick: function(event) {
this.setState({liked: !this.state.liked});
},
render: function() {
var text = this.state.liked ? 'like' : 'haven\'t liked';
return (
<p onClick={this.handleClick}>
You {text} this. Click to toggle.
</p>
);
}
});
ReactDOM.render(
<LikeButton />,
document.getElementById('example')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment