Skip to content

Instantly share code, notes, and snippets.

@gaearon
Created August 25, 2016 19:12
Show Gist options
  • Save gaearon/ee829ad9c814d25248aae60a0272007a to your computer and use it in GitHub Desktop.
Save gaearon/ee829ad9c814d25248aae60a0272007a to your computer and use it in GitHub Desktop.
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