Skip to content

Instantly share code, notes, and snippets.

@caelinsutch
Created February 3, 2021 09:48
Show Gist options
  • Save caelinsutch/f78adb8de463f4ec58e6b8f4587a773a to your computer and use it in GitHub Desktop.
Save caelinsutch/f78adb8de463f4ec58e6b8f4587a773a to your computer and use it in GitHub Desktop.
Buggy Counter
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