1.0.4 • Published 5 years ago
use-error-boundary-hook v1.0.4
use-error-boundary-hook
A React hook that allows you to use an error boundary in functional components.
Install
npm i use-errour-boundary-hookExample
import useErrorBoundary from 'use-error-boundary-hook';
function MyComponent(props) {
const [Try, Catch] = useErrorBoundary();
return (
<Try>
This is my content.
</Try>
<Catch>
Fallback content!
</Catch>
);
}The hook returns more than just the Try and Catch component:
const [Try, Catch, { hasError, error, errorInfo }] = useErrorBoundary();| Property | Type | |
|---|---|---|
hasError | Boolean | true if an error has been caught |
| error | ErrorObject or null | See React Docs |
| errorInfo | Object or null | See React Docs |