# State async and sync ```javascript= class App extends React.Component { constructor(props) { super(props); this.state = { num: 0 } this.handlerClick = this.handlerClick.bind(this); } handlerClick() { // async - object compare this.setState({ num: this.state.num + 1 }) this.setState({ num: this.state.num + 1 }) this.setState({ num: this.state.num + 1 }) // result = 1 // sync - unable to compare functions // this.setState((prevState) => ({ // num: prevState.num + 1 // })) // this.setState((prevState) => ({ // num: prevState.num + 1 // })) // this.setState((prevState) => ({ // num: prevState.num + 1 // })) // result = 3 } render() { return ( <div> <div>{ this.state.num }</div> <br /> <button onClick={this.handlerClick}>Change number</button> </div> ) } } ReactDOM.render(<App />, document.querySelector("#mountNode")) ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up