Guest User

Untitled

a guest
Jan 16th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. class Counter extends React.Component {
  2. constructor(props) {
  3. super(props);
  4. this.state = { counter: 0 };
  5. }
  6.  
  7. handleClick = () => {
  8. this.setState(({ counter }) => ({
  9. counter: counter + 1
  10. }));
  11. };
  12.  
  13. simError = () => {
  14. x / 2;
  15. };
  16.  
  17. render() {
  18. if (this.state.counter === 5) {
  19. // Simulate a JS error x is not defined
  20. // this will crash the component `this.simErro()`
  21. //this.simError()
  22. // but this will not `setTimeout(this.simError, 0);`
  23. //setTimeout(this.simError, 0);
  24. }
  25. return <h1 onClick={this.handleClick}>{this.state.counter}</h1>;
  26. }
  27. }
Add Comment
Please, Sign In to add comment