Guest User

Untitled

a guest
Jul 17th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. class Counter extends React.Component {
  2. constructor(props) {
  3. super(props);
  4. this.state = {
  5. count: 0
  6. };
  7. // change code below this line
  8. this.increment = this.increment.bind(this);
  9. this.decrement = this.decrement.bind(this);
  10. this.reset = this.reset.bind(this);
  11. // change code above this line
  12. }
  13. // change code below this line
  14. increment(){
  15. this.setState({count: this.state.count+1});
  16. }
  17. decrement(){
  18. this.setState({count : this.state.count-1});
  19. }
  20. reset(){
  21. this.setState({count : 0});
  22. }
  23. // change code above this line
  24. render() {
  25. return (
  26. <div>
  27. <button className='inc' onClick={this.increment}>Increment!</button>
  28. <button className='dec' onClick={this.decrement}>Decrement!</button>
  29. <button className='reset' onClick={this.reset}>Reset</button>
  30. <h1>Current Count: {this.state.count}</h1>
  31. </div>
  32. );
  33. }
  34. }
Add Comment
Please, Sign In to add comment