Created
November 23, 2017 15:33
-
-
Save HollyBang/fc604aae46f9032e556f4d1bc7e693da to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import React, { Component } from 'react'; | |
| class ErrorBoundary extends Component { | |
| state = { | |
| hasError: false, | |
| errorMessage: '' | |
| } | |
| componentDidCatch = (error, info) => { | |
| this.setState({hasError: true, errorMessage: error}); | |
| } | |
| render() { | |
| if (this.state.hasError) { | |
| return <h1>{this.state.errorMessage}</h1>; | |
| } else { | |
| 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