You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
634 B
26 lines
634 B
import React from 'react'
|
|
export default class ErrorBoundary extends React.Component {
|
|
constructor(props) {
|
|
super(props)
|
|
this.state = { hasError: false }
|
|
}
|
|
|
|
static getDerivedStateFromError(error) {
|
|
// Update state so the next render will show the fallback UI.
|
|
return { hasError: true }
|
|
}
|
|
|
|
componentDidCatch(error, errorInfo) {
|
|
// You can also log the error to an error reporting service
|
|
console.log(error, errorInfo)
|
|
}
|
|
|
|
render() {
|
|
if (this.state.hasError) {
|
|
// You can render any custom fallback UI
|
|
return <h1>Something went wrong.</h1>
|
|
}
|
|
|
|
return this.props.children
|
|
}
|
|
} |