use-error-boundary-hook
v1.0.4
Published
A React hook that allows you to use an error boundary in functional components
Downloads
5
Readme
use-error-boundary-hook
A React hook that allows you to use an error boundary in functional components.
Install
npm i use-errour-boundary-hook
Example
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 |