Passed
Push — master ( f602d8...7b3414 )
by Huu-Phat
02:55 queued 11s
created

modules/core/components/ErrorBoundary.js   A

Complexity

Total Complexity 3
Complexity/F 1.5

Size

Lines of Code 32
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 24
mnd 1
bc 1
fnc 2
dl 0
loc 32
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 5 1
A ErrorBoundary.render 0 8 2
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