# react-resilient

> A high order component for resiliently render errored components

Latest version **1.1.1** (published 2017-07-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-resilient
pnpm add react-resilient
yarn add react-resilient
bun add react-resilient
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2017-07-17 |
| First published | 2017-03-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 40 |
| Author | Albert Fernández |
| Maintainers | albertfdp |

## Links

- npm: https://www.npmjs.com/package/react-resilient
- Repository: https://github.com/albertfdp/react-resilient
- Homepage: https://github.com/albertfdp/react-resilient#readme
- Issues: https://github.com/albertfdp/react-resilient/issues
- npm.io page: https://npm.io/package/react-resilient

## Recent versions

- 1.1.1 (latest) — 2017-07-17
- 1.1.0 — 2017-07-17
- 1.0.0 — 2017-03-29
- 0.3.0 — 2017-03-29

## README

# react-resilient

[![Build Status](https://travis-ci.org/albertfdp/react-resilient.svg?branch=master)](https://travis-ci.org/albertfdp/react-resilient)
[![npm version](https://badge.fury.io/js/react-resilient.svg)](https://badge.fury.io/js/react-resilient)

A React component for resiliently render components that might fail. It wraps them around a React Fiber error boundary.

* Tries to render your component
* Renders `<FallbackComponent />` after the maximum number of retries (`props.maxRetries`)

---

#### ⚠️ DISCLAIMER: Experimental
This is **experimental** and **unstable** React API. It will be fully supported with `react@16.0.0` with first-level support `componentDidCatch`: https://github.com/facebook/react/pull/10200.

---

### [Demo](https://albertfdp.github.io/react-resilient)

```js
import React from 'react'
import Resilient from 'react-resilient'

const Broken = () => {
  throw new Error('Broken!')
}

const FallbackComponent = () => (
  <div>This is my fallback</div>
)

export default class Application extends React.Component {
  onError = (error) => {
    console.error('Error catched', error)
  }
  
  render () {
    return (
      <Resilient
        FallbackComponent={FallbackComponent}
        maxRetries={2}
        onError={this.onError}
      >
        <Broken />
      </Resilient>
    )
  }
}
```

### API

```js
<Resilient
  FallbackComponent={React.Component}
  maxRetries={number}
  onError={func}
>
  <YourComponent />
</Resilient>
```

##### `props.FallbackComponent (optional, defaults to render null)`

React component displayed after the `maxRetries`

##### `props.maxRetries` (optional, defaults to 0)

Number of retries before showing the `FallbackComponent`

##### `props.onError` (optional)

Callback for when errors are thrown

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