Passed
Push — master ( 33ec61...7df64f )
by Huu-Phat
24:11 queued 20:21
created

ErrorBoundary.render   A

Complexity

Conditions 2

Size

Total Lines 8
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 8
ccs 3
cts 3
cp 1
c 0
b 0
f 0
rs 10
cc 2
crap 2
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