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

ErrorBoundary.componentDidCatch   A

Complexity

Conditions 1

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
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