Created
February 3, 2021 09:48
-
-
Save caelinsutch/f78adb8de463f4ec58e6b8f4587a773a to your computer and use it in GitHub Desktop.
Buggy Counter
This file contains hidden or 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
class BuggyCounter extends Component { | |
state = { | |
counter: 0 | |
}; | |
handleClick = () => { | |
this.setState({ | |
counter: this.state.counter + 1 | |
}); | |
} | |
render() { | |
if (this.state.counter === 5) { | |
// Simulate an error! | |
throw new Error('I crashed!'); | |
} | |
return ( | |
<div> | |
<h1>{this.state.counter}</h1> | |
<button onClick={this.handleClick}>+</button> | |
</div> | |
); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment