Skip to content

Instantly share code, notes, and snippets.

@izabellewilding
Created July 9, 2020 21:03
Show Gist options
  • Save izabellewilding/23410c2a2257e2b0d106456c06428845 to your computer and use it in GitHub Desktop.
Save izabellewilding/23410c2a2257e2b0d106456c06428845 to your computer and use it in GitHub Desktop.
class ErrorBoundary extends React.Component {
constructor(props) {
super(props)
this.state = { error: null }
}
componentDidCatch(error) {
this.setState({
error,
})
}
render() {
if (this.state.error) {
// You can render any custom fallback UI
return <h1>Something went wrong.</h1>
}
return this.props.children
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment