import { Component , ErrorInfo , ReactElement } from 'react' ; interface Props { children : ReactElement ; } interface State { error : Error | null ; } export default class ErrorBoundary extends Component < Props , State > { constructor ( props ) { super ( props ) ; this . state = { error : null } ; } static getDerivedStateFromError ( error ) { return { error } ; } componentDidCatch ( error , errorInfo ) { console . error ( { error , errorInfo } ) ; } render ( ) { if ( this . state . error ) { return < h1 > Something went wrong . Error : { this . state . error . message } < /h1>; } return this . props . children ; } }