import React , { Component , ErrorInfo , ReactNode } from 'react' ; export type ErrorBoundaryOnError = ( error : Error , info : ErrorInfo ) => void ; export interface ErrorBoundaryState { error ? : Error ; } export interface ErrorBoundaryProps { onError ? : ErrorBoundaryOnError ; fallback ? : ReactNode ; children ? : ReactNode ; } export default class ErrorBoundary extends Component < ErrorBoundaryProps , ErrorBoundaryState > { constructor ( props ) { super ( props ) ; this . state = { } ; } static getDerivedStateFromError ( error ) { return { error , } ; } componentDidCatch ( error , info ) { const { onError } = this . props ; onError ?. ( error , info ) ; } render ( ) { const { state : { error } , props : { fallback , children } } = this ; if ( error ) { return < > { fallback } < />; } return < > { children } < />; } }