Created
April 16, 2018 03:33
-
-
Save shauntir/36fcf7eb2de5170c8130f1594aa352b0 to your computer and use it in GitHub Desktop.
Revisions
-
shauntir created this gist
Apr 16, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ import React, { Component } from 'react'; class ErrorrHandler extends Component { constructor(props) { super(props); this.state = { hasError: false }; } componentDidCatch(error, info) { this.setState({ hasError: true }); this.logError(error, info); } logError = (error, info) => { //Submit the error to some kind of logging service if available } render() { if (!this.state.hasError) { return this.props.children; } return ( <span> <h2>An error has occured</h2> </span> ); } } export default ErrorrHandler;