Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. class Counter extends React.Component {
  2. constructor() {
  3. super();
  4. this.state = {
  5. count: 0,
  6. }
  7. this.handleClick = this.handleClick.bind(this);
  8. }
  9.  
  10. handleClick = () => {
  11. const newCount = this.state.count + 1;
  12. this.setState({count: newCount});
  13. }
  14.  
  15. render() {
  16. const { count } = this.state;
  17. return (
  18. <div>
  19. <p> You've clicked the button {count} times. </p>
  20. <button onClick={this.handleClick}>Click Me </button>
  21.  
  22. </div>
  23. )
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement