UNPKG

@chatui/core

Version:

The React library for Chatbot UI

58 lines 2.4 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 _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf"; import _inherits from "@babel/runtime/helpers/esm/inherits"; var _excluded = ["FallbackComponent", "children"]; function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } import React from 'react'; export var ErrorBoundary = /*#__PURE__*/function (_React$Component) { function ErrorBoundary(props) { var _this; _classCallCheck(this, ErrorBoundary); _this = _callSuper(this, ErrorBoundary, [props]); _this.state = { error: null, errorInfo: null }; return _this; } _inherits(ErrorBoundary, _React$Component); return _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; } }]); }(React.Component);