Files
Iris/src/js/components/ErrorBoundary.js
James Barnsley 1ce85499f9 Eslint autofix
2021-03-23 21:21:00 +13:00

38 lines
847 B
JavaScript
Executable File

import React from 'react';
import ErrorMessage from './ErrorMessage';
export default class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = {
hasError: false,
error: null,
info: {},
};
}
componentDidCatch(error, info) {
this.setState({
hasError: true,
error,
info,
});
console.error(error, info);
}
render = () => {
const { hasError, info: { componentStack } = {} } = this.state;
const { children, silent } = this.props;
if (hasError) {
if (silent) return null;
return (
<ErrorMessage type="error-boundary">
{componentStack && <pre className="error-message__trace">{componentStack}</pre>}
</ErrorMessage>
);
}
return children;
}
}