error-boundary-jsx
TypeScript icon, indicating that this package has built-in type declarations

2.0.6 • Public • Published

npm npm bundle size Build Status codecov dependabot badge semantic-release Commitizen friendly

error-boundary-jsx

Handle errors on wrapped component and provide a fall back.

yarn add error-boundary-jsx
 
# or with npm 
 
npm install error-boundary-jsx --save

<ErrorBoundary /> Component (Recommended)

Handle errors for specific use case of component.

import ErrorBoundary from 'error-boundary-jsx'
 
<ErrorBoundary onError={componentErrorHandler} name="component name" FallbackComponent={CustomFallbackComponent}>
    ...component tree to handle errors
</ErrorBoundary>

withErrorBoundary() HOC

HOC for error handling every use case of a component.

import withErrorBoundary from 'error-boundary-jsx'
 
const componentErrorHandler = {
    handleComponentError(error: Error, name: string, stack: string): void {
        ...log error
    }
}
 
withErrorBoundary(Component, componentErrorHandler)
API
prop type required defaultValue Description
component React.ComponentType true - A component that we want to bind error boundary jsx to
name string true - Component name to identify in stack message
onError (name: string, error: Error, stack: string) => void true - Error callback handler
FallbackComponent React.ComponentType false - A fallback component when error occurs

Dependencies (0)

    Dev Dependencies (4)

    Package Sidebar

    Install

    npm i error-boundary-jsx

    Weekly Downloads

    1

    Version

    2.0.6

    License

    MIT

    Unpacked Size

    14.3 kB

    Total Files

    18

    Last publish

    Collaborators

    • monkey3310