import { Component , ErrorInfo } from "react" ; export class TestErrorBoundary extends Component < { onError : ( error : Error , errorInfo : ErrorInfo ) => void ; } , { hasError : boolean ; } > { state = { hasError : false , } ; componentDidCatch ( error , errorInfo ) { this . props . onError ( error , errorInfo ) ; } static getDerivedStateFromError ( ) { return { hasError : true } ; } render ( ) { if ( this . state . hasError ) { return "error" ; } return this . props . children ; } }