1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-22 21:14:18 +00:00
pds-2021-g2-nest/nest_frontend/components/boundaries/ErrorBoundary.js

28 lines
680 B
JavaScript
Raw Normal View History

2021-05-24 12:49:59 +00:00
import React from "react"
import AlertError from "../interactive/AlertError"
export default class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = {error: null}
}
static getDerivedStateFromError(error) {
// I'm not too sure on what this does
return {error}
}
componentDidCatch(error, errorInfo) {
console.error("Caught error ", error, " with info ", errorInfo)
this.setState(state => state.error = error)
}
render() {
if(this.state.error) {
return <AlertError error={this.state.error}/>
}
return this.props.children
}
}