for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
import React, { Component } from 'react'
export default class ErrorBoundary extends Component {
constructor(props) {
super(props)
this.state = { hasError: false }
}
static getDerivedStateFromError() {
return { hasError: true }
componentDidCatch(error, errorInfo) {
// eslint-disable-next-line no-console
console.log(error, errorInfo)
render() {
// eslint-disable-next-line react/destructuring-assignment
if (this.state.hasError) {
return <h1>Something went wrong.</h1>
// eslint-disable-next-line react/destructuring-assignment, react/prop-types
return this.props.children