Created
August 25, 2016 19:12
-
-
Save gaearon/ee829ad9c814d25248aae60a0272007a 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 Boundary extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { err: null }; | |
} | |
unstable_handleError(err) { | |
report(err); | |
this.setState({ err }) | |
} | |
render() { | |
return this.state.err ? <ErrorPage /> : this.props.children; | |
} | |
} | |
// Usage: | |
// <Boundary><ComponentThatMayThrow /></Boundary> | |
// Currently only works for mounting. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment