UNPKG

samagra-chatui

Version:
60 lines 2.75 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; import _createClass from "@babel/runtime/helpers/esm/createClass"; import _inherits from "@babel/runtime/helpers/esm/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf"; var _excluded = ["FallbackComponent", "children"]; function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } import React from 'react'; export var ErrorBoundary = /*#__PURE__*/function (_React$Component) { _inherits(ErrorBoundary, _React$Component); var _super = _createSuper(ErrorBoundary); function ErrorBoundary(props) { var _this; _classCallCheck(this, ErrorBoundary); _this = _super.call(this, props); _this.state = { error: null, errorInfo: null }; return _this; } _createClass(ErrorBoundary, [{ key: "componentDidCatch", value: function componentDidCatch(error, errorInfo) { var onError = this.props.onError; if (onError) { onError(error, errorInfo); } this.setState({ error: error, errorInfo: errorInfo }); } }, { key: "render", value: function render() { var _this$props = this.props, FallbackComponent = _this$props.FallbackComponent, children = _this$props.children, rest = _objectWithoutProperties(_this$props, _excluded); var _this$state = this.state, error = _this$state.error, errorInfo = _this$state.errorInfo; if (errorInfo) { if (FallbackComponent) { return /*#__PURE__*/React.createElement(FallbackComponent, _extends({ error: error, errorInfo: errorInfo }, rest)); } return null; } return children; } }]); return ErrorBoundary; }(React.Component);