Passed
Pull Request — master (#2)
by
unknown
02:27
created

src/utils/ErrorBoundary.js   A

Complexity

Total Complexity 4
Complexity/F 1.33

Size

Lines of Code 28
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 20
mnd 1
bc 1
fnc 3
dl 0
loc 28
bpm 0.3333
cpm 1.3333
noi 0
c 0
b 0
f 0
rs 10

3 Functions

Rating   Name   Duplication   Size   Complexity  
A ErrorBoundary.getDerivedStateFromError 0 3 1
A ErrorBoundary.componentDidCatch 0 4 1
A ErrorBoundary.render 0 9 2
1
import React, { Component } from 'react'
2
3
export default class ErrorBoundary extends Component {
4
  constructor(props) {
5
    super(props)
6
    this.state = { hasError: false }
7
  }
8
9
  static getDerivedStateFromError() {
10
    return { hasError: true }
11
  }
12
13
  componentDidCatch(error, errorInfo) {
14
    // eslint-disable-next-line no-console
15
    console.log(error, errorInfo)
16
  }
17
18
  render() {
19
    // eslint-disable-next-line react/destructuring-assignment
20
    if (this.state.hasError) {
21
      return <h1>Something went wrong.</h1>
22
    }
23
24
    // eslint-disable-next-line react/destructuring-assignment, react/prop-types
25
    return this.props.children
26
  }
27
}
28