import {Component} from 'react'; import RouteError from 'sentry/views/routeError'; type State = { error: Error | undefined; hasError: boolean; }; export default function errorHandler

(WrappedComponent: React.ComponentType

) { class ErrorHandler extends Component { static getDerivedStateFromError(error: Error) { // Update state so the next render will show the fallback UI. return { hasError: true, error, }; } state: State = { // we are explicit if an error has been thrown since errors thrown are not guaranteed // to be truthy (e.g. throw null). hasError: false, error: undefined, }; componentDidCatch(_error: Error, info: React.ErrorInfo) { // eslint-disable-next-line no-console console.error( 'Component stack trace caught in :', info.componentStack ); } render() { if (this.state.hasError) { return ; } return ; } } return ErrorHandler; }