-
-
Save gaearon/a9bbb73d57b6e4cc17d7b50807b62f9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
class Counter extends Component { | |
state = { value: 0 }; | |
increment = () => { | |
this.setState(prevState => ({ | |
value: prevState.value + 1 | |
})); | |
}; | |
decrement = () => { | |
this.setState(prevState => ({ | |
value: prevState.value - 1 | |
})); | |
}; | |
render() { | |
return ( | |
<div> | |
{this.state.value} | |
<button onClick={this.increment}>+</button> | |
<button onClick={this.decrement}>-</button> | |
</div> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment