Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Counter extends React.Component {
- constructor(props) {
- super(props);
- this.state = { counter: 0 };
- }
- handleClick = () => {
- this.setState(({ counter }) => ({
- counter: counter + 1
- }));
- };
- simError = () => {
- x / 2;
- };
- render() {
- if (this.state.counter === 5) {
- // Simulate a JS error x is not defined
- // this will crash the component `this.simErro()`
- //this.simError()
- // but this will not `setTimeout(this.simError, 0);`
- //setTimeout(this.simError, 0);
- }
- return <h1 onClick={this.handleClick}>{this.state.counter}</h1>;
- }
- }
Add Comment
Please, Sign In to add comment