import React , { Component , ReactNode } from 'react' ; import { SettingsSpec } from '../../specs/settings' ; import { NoResults } from '../no_results' ; import { isGracefulError } from './errors' ; type ErrorBoundaryProps = { children : ReactNode ; renderFn ? : SettingsSpec [ 'noResults' ] ; } ; interface ErrorBoundaryState { hasError : boolean ; } internal export class ErrorBoundary extends Component < ErrorBoundaryProps , ErrorBoundaryState > { hasError = false ; componentDidUpdate ( ) { if ( this . hasError ) { this . hasError = false ; } } componentDidCatch ( error ) { if ( isGracefulError ( error ) ) { this . hasError = true ; this . forceUpdate ( ) ; } } render ( ) { if ( this . hasError ) { return < NoResults renderFn = { this . props . renderFn } />; } return this . props . children ; } }