| Total Complexity | 3 |
| Complexity/F | 1.5 |
| Lines of Code | 32 |
| 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 '~/modules/core/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 { |
|
| 13 | errorTrace: error, |
||
| 14 | hasError: true |
||
| 15 | } |
||
| 16 | } |
||
| 17 | |||
| 18 | render() { |
||
| 19 | 3 | if (this.state.hasError) { |
|
| 20 | // You can render any custom fallback UI |
||
| 21 | 1 | return <Error /> |
|
| 22 | } |
||
| 23 | |||
| 24 | 2 | return this.props.children |
|
| 25 | } |
||
| 26 | } |
||
| 27 | 1 | ErrorBoundary.propTypes = { |
|
| 28 | children: PropTypes.any |
||
| 29 | } |
||
| 30 | |||
| 31 | export default ErrorBoundary |
||
| 32 |