UNPKG

@krmao/react-basic

Version:
30 lines (29 loc) 1.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var react_1 = (0, tslib_1.__importStar)(require("react")); var BasicAsyncComponent = function (component) { return /** @class */ (function (_super) { (0, tslib_1.__extends)(_, _super); function _() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.state = { component: undefined }; return _this; } _.prototype.componentDidMount = function () { var _this = this; component().then(function (cmp) { _this.setState({ component: cmp.default }); }); }; _.prototype.render = function () { var C = this.state.component; // @ts-ignore return C ? react_1.default.createElement(C, (0, tslib_1.__assign)({}, this.props)) : null; }; return _; }(react_1.Component)); }; exports.default = BasicAsyncComponent;