@tacky/store
Version:
State management framework based on react
57 lines (44 loc) • 2.04 kB
JavaScript
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";
function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { 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 { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
import * as React from 'react';
var ErrorBoundary = /*#__PURE__*/function (_React$Component) {
_inherits(ErrorBoundary, _React$Component);
var _super = _createSuper(ErrorBoundary);
function ErrorBoundary() {
var _this;
_classCallCheck(this, ErrorBoundary);
_this = _super.apply(this, arguments);
_this.state = {
hasError: false,
error: {
message: ''
}
};
return _this;
}
_createClass(ErrorBoundary, [{
key: "componentDidCatch",
value: function componentDidCatch(error) {
this.setState({
hasError: true,
error: error
});
}
}, {
key: "render",
value: function render() {
var message = this.state.error.message;
if (this.state.hasError) {
return React.createElement("h2", null, "Something went wrong. Error: ", message);
}
return this.props.children;
}
}]);
return ErrorBoundary;
}(React.Component);
export { ErrorBoundary as default };