| Total Complexity | 3 |
| Complexity/F | 1.5 |
| Lines of Code | 30 |
| Function Count | 2 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | import React from 'react' |
||
| 2 | import PropTypes from 'prop-types' |
||
| 3 | import Error from 'error/components/Error' |
||
| 4 | |||
| 5 | class ErrorBoundary extends React.Component { |
||
| 6 | constructor(props) { |
||
| 7 | 2 | super(props) |
|
| 8 | 2 | this.state = { hasError: false } |
|
| 9 | } |
||
| 10 | |||
| 11 | static getDerivedStateFromError(error) { |
||
| 12 | 1 | return { error, hasError: true } |
|
| 13 | } |
||
| 14 | |||
| 15 | render() { |
||
| 16 | 4 | if (this.state.hasError || this.props.reduxError) { |
|
| 17 | // You can render any custom fallback UI |
||
| 18 | 2 | return <Error error={this.props.reduxError || this.state.error} /> |
|
| 19 | } |
||
| 20 | |||
| 21 | 1 | return this.props.children |
|
| 22 | } |
||
| 23 | } |
||
| 24 | 1 | ErrorBoundary.propTypes = { |
|
| 25 | children: PropTypes.any, |
||
| 26 | reduxError: PropTypes.object |
||
| 27 | } |
||
| 28 | |||
| 29 | export default ErrorBoundary |
||
| 30 |