Created
July 9, 2020 21:03
-
-
Save izabellewilding/23410c2a2257e2b0d106456c06428845 to your computer and use it in GitHub Desktop.
This file contains 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 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