use-error-boundary-hook

1.0.4 • Public • Published

use-error-boundary-hook

npm version license

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

Package Sidebar

Install

npm i use-error-boundary-hook

Weekly Downloads

1

Version

1.0.4

License

MIT

Unpacked Size

11.1 kB

Total Files

5

Last publish

Collaborators

  • brams-dev