Skip to content

Instantly share code, notes, and snippets.

@bcuz
Created October 2, 2017 15:10
Show Gist options
  • Save bcuz/1caa2a9e47a56676795c62571a302805 to your computer and use it in GitHub Desktop.
Save bcuz/1caa2a9e47a56676795c62571a302805 to your computer and use it in GitHub Desktop.
class MyComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
itemCount: 0
};
this.addItem = this.addItem.bind(this);
}
addItem() {
this.setState({
itemCount: this.state.itemCount + 1
});
}
render() {
return (
<div>
<button onClick = {this.addItem}>Click Me</button>
<h1>Current Item Count: {this.state.itemCount}</h1>
</div>
);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment