Socket
Book a DemoInstallSign in
Socket

react-resilient

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-resilient

A high order component for resiliently render errored components

latest
Source
npmnpm
Version
1.1.1
Version published
Maintainers
1
Created
Source

react-resilient

Build Status npm version

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

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

<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

FAQs

Package last updated on 17 Jul 2017

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