import React from 'react' ; interface State { hasError : boolean ; } export default class ErrorBoundary extends React . Component < any , State > { constructor ( props ) { super ( props ) ; this . state = { hasError : false } ; } static getDerivedStateFromError ( error ) { return { hasError : true , error } ; } componentDidCatch ( error , errorInfo ) { console . error ( error , errorInfo ) ; } render ( ) { const { hasError } = this . state ; if ( hasError ) { return < div > Something went wrong . < /div>; } const { children } = this . props ; return children ; } }