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
)
This is experimental and unstable React API. It will be fully supported with react@next
(Fiber).
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>
)
}
}
<Resilient
FallbackComponent={React.Component}
maxRetries={number}
onError={func}
>
<YourComponent />
</Resilient>
React component displayed after the maxRetries
Number of retries before showing the FallbackComponent
Callback for when errors are thrown