UNPKG

@shopgate/pwa-common

Version:

Common library for the Shopgate Connect PWA.

57 lines (54 loc) 1.47 kB
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose"; import { PureComponent } from 'react'; import PropTypes from 'prop-types'; import connector from "./connector"; /** * The App error boundary component. */ let ErrorBoundary = /*#__PURE__*/function (_PureComponent) { /** * Constructor for the ErrorBoundary component. * @param {Object} props - The component props. */ function ErrorBoundary(props) { var _this; _this = _PureComponent.call(this, props) || this; _this.state = { hasError: false }; return _this; } /** * @param {Object} error The error object. * @param {Object} errorInfo The error information. */ _inheritsLoose(ErrorBoundary, _PureComponent); /** * @returns {{hasError: boolean}} */ ErrorBoundary.getDerivedStateFromError = function getDerivedStateFromError() { return { hasError: true }; }; var _proto = ErrorBoundary.prototype; _proto.componentDidCatch = function componentDidCatch(error, errorInfo) { // eslint-disable-next-line no-param-reassign error.stack = errorInfo.componentStack; this.props.appError(error); } /** * @returns {JSX} */; _proto.render = function render() { if (this.state.hasError) { return this.props.fallbackUi; } return this.props.children; }; return ErrorBoundary; }(PureComponent); ErrorBoundary.defaultProps = { fallbackUi: null }; export default connector(ErrorBoundary);