Skip to content

albertfdp/react-resilient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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: facebook/react#10200.


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

About

🛡 A component that resiliently renders components that might fail

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy