Skip to content

Instantly share code, notes, and snippets.

@Anirudhk94
Last active January 11, 2019 20:11
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 Anirudhk94/369481d99b23d3d5333042ebdaf64457 to your computer and use it in GitHub Desktop.
Save Anirudhk94/369481d99b23d3d5333042ebdaf64457 to your computer and use it in GitHub Desktop.
class Button extends React.Component {
//prevState to avoid race condition
state = {counter : 0};
changeLabel = () => {
this.setState((prevState) => {
return {
counter: prevState.counter + 1
}
})
}
render() {
return(
<button onClick={this.changeLabel}>
{this.state.counter}
</button>
)
}
}
ReactDOM.render(<Button />, mountNode)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment