import React from 'react' ; type Props = { children : React . ReactNode ; } ; type State = { error : Error | null ; } ; export default class ErrorBoundary extends React . Component < Props , State > { state = { error : null } ; static getDerivedStateFromError ( error ) { return { error , } ; } render ( ) { if ( this . state . error != null ) { return ( < div > < div > Error : { this . state . error . message } < /div> < div > < pre > { JSON . stringify ( this . state . error . source , null , 2 ) } < /pre> < /div> < /div>); } return this . props . children ; } }