Passed
Push — master ( 6fca9e...82ba0d )
by Huu-Phat
02:25 queued 10s
created

cms/src/error/components/ErrorBoundary.js   A

Complexity

Total Complexity 3
Complexity/F 1.5

Size

Lines of Code 30
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 23
mnd 1
bc 1
fnc 2
dl 0
loc 30
ccs 7
cts 7
cp 1
bpm 0.5
cpm 1.5
noi 0
c 0
b 0
f 0
rs 10

2 Functions

Rating   Name   Duplication   Size   Complexity  
A ErrorBoundary.getDerivedStateFromError 0 3 1
A ErrorBoundary.render 0 8 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