github.com/replicatedhq/ship@v0.55.0/web/init/src/ErrorBoundary.jsx (about) 1 import React from "react"; 2 import classNames from "classnames"; 3 /** 4 * Creates an error boundary for any child component rendered inside 5 */ 6 export default class ErrorBoundary extends React.Component { 7 constructor(props) { 8 super(props); 9 this.state = { 10 error: null, 11 errorInfo: null, 12 hasError: false 13 } 14 } 15 16 static getDerivedStateFromError(error) { 17 return { 18 error, 19 hasError: true 20 }; 21 } 22 23 componentDidCatch() { 24 // We can thow an error modal, or some sort of error UI that can be used globally. 25 // We should also send this error to bugsnag or some sort of reporting service here. 26 } 27 28 render() { 29 const { children, className } = this.props; 30 const { hasError, error } = this.state; 31 return ( 32 <div className={classNames("flex flex1", className)}> 33 {hasError && <div>{error.toString()}</div>} 34 {children} 35 </div> 36 ); 37 } 38 }