JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 44290
  • Score
    100M100P100Q149636F
  • License MIT

React hook for using error boundaries

Package Exports

  • use-error-boundary

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (use-error-boundary) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

React useErrorBoundary() hook

build status

This react hook provides a ErrorBoundary class and the error state of the error boundary.

The ErrorBoundary is implemented using classes (as there is no hook-based componentDidCatch implementation yet).

Installation

npm install --save use-error-boundary

Usage

import React from "react"
import { useErrorBoundary } from "use-error-boundary"

const myComponent = () => {
  const { ErrorBoundary, didCatch, error, errorInfo } = useErrorBoundary()

  if (didCatch) return <h1>Something went wrong</h1>

  return (
    <ErrorBoundary>
      <SomeChildren />
    </ErrorBoundary>
  )
}