# react-native-error-helper

> A helper for React Native to catch global JS errors and provide some ways to resolve error boundaries

Latest version **0.2.2** (published 2021-04-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-native-error-helper
pnpm add react-native-error-helper
yarn add react-native-error-helper
bun add react-native-error-helper
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2021-04-23 |
| First published | 2021-04-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 19 |
| Author | iChengbo |
| Maintainers | chengbo |
| Keywords | react, native, error, helper, boundary, hoc |

## Links

- npm: https://www.npmjs.com/package/react-native-error-helper
- Repository: https://github.com/iChengbo/react-native-error-helper
- Homepage: https://github.com/iChengbo/react-native-error-helper#readme
- Issues: https://github.com/iChengbo/react-native-error-helper/issues
- npm.io page: https://npm.io/package/react-native-error-helper

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 0.2.2 (latest) — 2021-04-23
- 0.2.1 — 2021-04-22
- 0.2.0 — 2021-04-22
- 0.1.0 — 2021-04-20
- 0.0.3 — 2021-04-19
- 0.0.2 — 2021-04-19
- 0.0.1 — 2021-04-18

## README

# react-native-error-helper

> A helper for React Native to catch global JS errors and provide some ways to resolve error boundaries.


![LICENSE](https://img.shields.io/badge/license-MIT-blue) ![npm-version](https://img.shields.io/npm/v/react-native-error-helper) ![npm](https://img.shields.io/npm/dm/react-native-error-helper.svg)


<!-- [![https://nodei.co/npm/react-native-error-helper.png?downloads=true&downloadRank=true&stars=true](https://nodei.co/npm/react-native-error-helper.png?downloads=true&downloadRank=true&stars=true)](https://www.npmjs.com/package/react-native-error-helper) -->


## Table of Contents
- [Install](#Install)
- [Usage](#Usage)
  - [setGlobalErrorHandler](#setGlobalErrorHandler)
  - [setPromiseUnCatchHandler](#setPromiseUnCatchHandler)
  - [ErrorBoundary](#ErrorBoundary)
  - [withErrorBoundary](#withErrorBoundary)
- [LICENSE](#LICENSE)


## Install

> yarn add react-native-error-helper

## Usage

### setGlobalErrorHandler

```js
import { setGlobalErrorHandler } from 'react-native-error-helper';

setGlobalErrorHandler((error, isFatal) => {
  console.log('global error：', error, isFatal);
}, true);
```

### setPromiseUnCatchHandler

```js
import { setPromiseUnCatchHandler } from 'react-native-error-helper';

setPromiseUnCatchHandler((id, err) => {
  console.log('promise un catch：', err);
}, true);
```

### ErrorBoundary

```js
import { ErrorBoundary } from 'react-native-error-helper';

const App = () => (
  <ErrorBoundary>
    <BugComponent />
  </ErrorBoundary>
)
```

### withErrorBoundary

```js
import { withErrorBoundary } from 'react-native-error-helper';

@withErrorBoundary({
  renderBoundary: ({error}) => {
    return <Text>catch error: {error.message}</Text>;
  },
})
class BuggyCounter extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      count: 0 || this.props.init,
    };
  }

  render() {
    const {count} = this.state;
    if (count === 5) {
      throw new Error('I error');
    } else {
      return (
        <View>
          <Text
            onPress={() => {
              this.setState({
                count: count + 1,
              });
            }}>
            {String(count)}
          </Text>
        </View>
      );
    }
  }
}
```

## LICENSE

MIT

---
_Source: https://npm.io/package/react-native-error-helper · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
