Creates an error boundary, using React's .componentDidCatch()
API.
import {ErrorBoundary} from 'libreact/lib/ErrorBoundary';
<ErrorBoundary
renderError={({error, info}) => <div>ERROR!</div>}
onError={({error, info}) => {/* ... */}}
>
<div>
This code is protected by error boundary.
</div>
</ErrorBoundary>
Signature
interface IErrorBoundaryProps {
renderError?: (state: IErrorBoundaryState) => React.ReactElement;
onError?: (error?: Error, info?) => void;
}
interface IErrorBoundaryState {
error?: Error;
info?: any;
}
, were
renderError
— renderer called if error happened in error boundary's children.onError
— event called every time error detected.
Wraps your component into an error boundary.
import {withErrorBoundary} from 'libreact/lib/ErrorBoundary';
const SafeComponent = withErrorBoundary(UnsafeComponent, {
renderError: () => <div>Error happened!</div>
});
Signature
withErrorBoundary(Comp, boundaryProps: IErrorBoundaryProps)