UNPKG

acud

Version:

acg react 组件库

62 lines • 2.42 kB
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 _isNativeReflectConstruct from "@babel/runtime/helpers/esm/isNativeReflectConstruct"; import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf"; import _inherits from "@babel/runtime/helpers/esm/inherits"; function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } /** * @file ErrorBoundary * @author jiangting01 */ import * as React from 'react'; import Alert from '.'; var ErrorBoundary = /*#__PURE__*/function (_React$Component) { function ErrorBoundary() { var _this; _classCallCheck(this, ErrorBoundary); _this = _callSuper(this, ErrorBoundary, arguments); _this.state = { error: undefined, info: { componentStack: '' } }; return _this; } _inherits(ErrorBoundary, _React$Component); return _createClass(ErrorBoundary, [{ key: "componentDidCatch", value: function componentDidCatch(error, info) { var _a, _b; this.setState({ error: error, info: info }); (_b = (_a = this.props).onError) === null || _b === void 0 ? void 0 : _b.call(_a, error, info); } }, { key: "render", value: function render() { var _this$props = this.props, message = _this$props.message, description = _this$props.description, children = _this$props.children; var _this$state = this.state, error = _this$state.error, info = _this$state.info; if (error) { var componentStack = (info === null || info === void 0 ? void 0 : info.componentStack) || null; var errorMessage = typeof message === 'undefined' ? (error || '').toString() : message; var errorDescription = typeof description === 'undefined' ? componentStack : description; return /*#__PURE__*/React.createElement(Alert, { type: "error", message: errorMessage, description: /*#__PURE__*/React.createElement("pre", null, errorDescription) }); } return children; } }]); }(React.Component); export { ErrorBoundary as default };