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

{'Something went wrong.'}

{`error: ${error}`}

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

); } return children; } }