Files
ontime/client/src/common/components/errorBoundary/ErrorBoundary.jsx
T
Carlos Valente 67ddcd8c68 Feat/table (#105)
* feat/table add react-table
* feat/table add protected table route
* feat/table upgrade dependencies
* feat/table support parsing of new properties

Co-authored-by: DeepSource Bot <bot@deepsource.io>
2022-04-09 22:05:56 +02:00

35 lines
786 B
React

/* eslint-disable react/destructuring-assignment */
import React from 'react';
import { LoggingContext } from '../../../app/context/LoggingContext';
class ErrorBoundary extends React.Component {
static contextType = LoggingContext;
constructor(props) {
super(props);
this.state = { error: null, errorInfo: null };
}
static getDerivedStateFromError(error) {
// Update state so next render shows fallback UI.
return { errorMessage: error.toString() };
}
componentDidCatch(error, info) {
this.setState({
error: error,
errorInfo: info,
});
this.context.emitError(error.toString());
}
render() {
if (this.state.errorMessage) {
return <p>:/</p>;
}
return this.props.children;
}
}
export default ErrorBoundary;