import React, { Component } from 'react'; export interface ErrorProps { children: any; } export interface ErrorAppState { hasError: boolean; error: Error | null; info: object | null; } export default class ErrorBoundary extends Component { constructor(props: ErrorProps) { super(props); this.state = { hasError: false, error: null, info: null }; } public componentDidCatch(error: Error, info: object) { this.setState({ hasError: true, error, info }); } public render(): JSX.Element { const { hasError, error, info } = this.state; const { children } = this.props; if (hasError) { return ( <>

{'Something went wrong.'}

{`error: ${error}`}

{`info: ${JSON.stringify(info)}`}

); } return children; } }