@xysfe/catch-react-error
Version:
react error boundaries
27 lines (24 loc) • 582 B
JavaScript
import * as React from 'react'
export default class DefaultErrorBoundary extends React.PureComponent {
constructor(props) {
super(props)
this.state = {
error: null
}
}
componentDidCatch(error, info) {
this.setState({ error })
if (this.props.throw) {
this.props.throw(error)
this.props.throw(info)
}
}
render() {
const { FallbackComponent } = this.props
const { error } = this.state
if (error && FallbackComponent) {
return FallbackComponent
}
return this.props.children
}
}