Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

use-error-boundary

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-error-boundary

React hook for using error boundaries

  • 1.0.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
18K
decreased by-26.45%
Maintainers
1
Weekly downloads
 
Created
Source

use-error-boundary

npm version build status license

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 i use-error-boundary

Functionality

The hook provides an ErrorBoundary class, that accepts children and renders them. In case of an exception, the ErrorBoundary will render null and the hook will update its state.

This lets you implement an error screen depending on the Status of the Error boundary, using function components and hooks!

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>
  )
}

Contributing

Contributions are welcome, as this is my first properly published npm package.

Feel free to open issues or pull requests! I will review them as fast as possible.

Keywords

FAQs

Package last updated on 21 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc