Skip to content

Instantly share code, notes, and snippets.

@Oliver-ke
Created January 4, 2021 09:16
Show Gist options
  • Save Oliver-ke/9b4b118d8de12708a06accbdd1983008 to your computer and use it in GitHub Desktop.
Save Oliver-ke/9b4b118d8de12708a06accbdd1983008 to your computer and use it in GitHub Desktop.
Snippet for react error boundary component
import React, {Component} from 'react';
class ErrorBoundary extends Component {
constructor(props) {
super(props)
this.state = {
hasError: false,
}
}
componentDidCatch(){
this.setState({
hasError: true
})
}
render() {
if(this.state.hasError) {
return <h2>Opss something went wrong</h2>
}
return this.props.children
}
}
export default ErrorBoundary;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment