@ima/react-page-renderer
Version:
IMA.js React page renderer.
36 lines (35 loc) • 1.01 kB
JavaScript
import { PureComponent } from 'react';
/**
* Error boundary wrapper which connects the IMA application to the
* dev HMR api and handles error reporting.
*/ export class ErrorBoundary extends PureComponent {
constructor(props){
super(props);
this.state = {
hasError: false
};
}
static getDerivedStateFromError() {
return {
hasError: true
};
}
componentDidMount() {
// Clear reported errors
if (typeof window !== 'undefined' && window?.__IMA_HMR?.emitter) {
window.__IMA_HMR.emitter.emit('clear');
}
}
componentDidCatch(error) {
// Report errors to overlay
if (typeof window !== 'undefined' && window?.__IMA_HMR?.emitter) {
window.__IMA_HMR.emitter.emit('error', {
error
});
}
}
render() {
return this.state.hasError ? null : this.props.children;
}
}
//# sourceMappingURL=ErrorBoundary.js.map