Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class MyComponent extends Component {
state = { hasError: false };
componentDidCatch(error, info) {
this.setState({ hasError: true });
}
render() {
const { hasError } = this.state
if (hasError) {
return <h1>Something went wrong.</h1>;
}
return <div>All good!</div>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.