Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/maniator/react-badly
Error boundary react component
https://github.com/maniator/react-badly
catch error-boundaries react react-16 tree
Last synced: about 2 months ago
JSON representation
Error boundary react component
- Host: GitHub
- URL: https://github.com/maniator/react-badly
- Owner: maniator
- Created: 2018-01-11T16:06:23.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-04-08T10:48:48.000Z (9 months ago)
- Last Synced: 2024-04-14T07:33:58.412Z (8 months ago)
- Topics: catch, error-boundaries, react, react-16, tree
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/react-badly
- Size: 4.09 MB
- Stars: 7
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
# react-badly
Take hold of your react lifecycle hooks with `react-badly`
[![npm version](https://badge.fury.io/js/react-badly.svg)](https://www.npmjs.com/package/react-badly)
You can install off of npm with
```shell
npm install react-badly# or yarn
yarn add react-badly
```This component is a wrapper for any of your React 16+ plus components that may have an error in them.
### How to use
The simplest way is to just wrap any component that you think may error with `ReactBadly`
This will prevent the component from rendering (also will stop any children in the tree as well).
This is to make sure that your **whole** component tree does not dismount as React 16+ does.```jsx harmony
import ReactBadly from 'react-badly';// some code later on
...
```
If you want to handle your error with some functionality (like sending to analytics etc) you can pass an `onError`
property which will get the error and any info as parameters from react.```jsx harmony
import ReactBadly from 'react-badly';const errorFunction = (error, info) => {
// can handle the error here and do what you will with it
};// some code later on
...
```
There may also be some cases where you actually want to render something else to display if there was an error instead
of just not displaying anything. To do that you can pass the `render` property which will accept a function that will
take in `{ error, info }` as a parameter. This will render **instead** of the direct child of `ReactBadly`.```jsx harmony
import ReactBadly from 'react-badly';const renderError = ({ error, info }) => (
You have an error!
{JSON.stringify(error)}'\n'{JSON.stringify(info)}
);// some code later on
...
```