Socket
Book a DemoInstallSign in
Socket

react-resilent

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-resilent

A high order component for resilently render errored components

latest
Source
npmnpm
Version
0.3.0
Version published
Maintainers
1
Created
Source

react-resilent

Build Status

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

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

⚠️ DISCLAIMER: Experimental

This ONLY works with react@next (Fiber).

Demo

import React from 'react'
import Resilent from 'react-resilent'

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

const ResilentComponent = Resilent({
  FallbackComponent: () => <div>Fallback component</div>
})(Broken)

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

API

const MyResilentComponent = Resilent({
  FallbackComponent: React.Component
})(React.Component)


<MyResilentComponent
  maxRetries={number}
  onError={func}
/>
opts.FallbackComponent

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 21 Mar 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