core-native
Version:
A lightweight framework based on React Native + Redux + Redux Saga, in strict TypeScript.
30 lines • 1.28 kB
JavaScript
import { __extends } from "tslib";
import React from "react";
/**
* CAVEAT:
* When using require("..").Component in React Native, the type info is discarded.
* If the Props of returned component is not {}, you should explicitly specify the generic <T> for the required component (but not recommended).
*/
export function async(componentLoader, loadingComponent) {
if (loadingComponent === void 0) { loadingComponent = null; }
return /** @class */ (function (_super) {
__extends(AsyncWrapperComponent, _super);
function AsyncWrapperComponent(props) {
var _this = _super.call(this, props) || this;
_this.state = { Component: null };
return _this;
}
AsyncWrapperComponent.prototype.componentDidMount = function () {
if (this.state.Component === null) {
var Component = componentLoader();
this.setState({ Component: Component });
}
};
AsyncWrapperComponent.prototype.render = function () {
var Component = this.state.Component;
return Component ? <Component {...this.props}/> : loadingComponent;
};
return AsyncWrapperComponent;
}(React.PureComponent));
}
//# sourceMappingURL=async.js.map