Skip to content

Instantly share code, notes, and snippets.

@chentsulin
Last active November 6, 2018 02:10
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 chentsulin/dcc48520aef326628b46ebb85a4bd3df to your computer and use it in GitHub Desktop.
Save chentsulin/dcc48520aef326628b46ebb85a4bd3df to your computer and use it in GitHub Desktop.
counter class
class Counter {
state = {
value: this.props.defaultValue
};
handlePlusOne = () => {
this.setState(() => ({ value: this.state.value + 1 }));
};
render() {
return (
<>
<div>{this.state.value}</div>
<button onClick={this.handlePlusOne}>+</button>
</>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment