import React , { ErrorInfo , PropsWithChildren } from 'react' ; interface ErrorBoundaryState { hasError : boolean ; } class ErrorBoundary extends React . Component < PropsWithChildren < { } > , ErrorBoundaryState > { constructor ( props ) { super ( props ) ; this . state = { hasError : false } ; } componentDidCatch ( _error , _info ) { this . setState ( { hasError : true } ) ; } render ( ) { if ( this . state . hasError ) { return < h1 > Something went wrong . < /h1>; } return this . props . children ; } } export default ErrorBoundary ;