core-native
Version:
A lightweight framework based on React Native + Redux + Redux Saga, in strict TypeScript.
25 lines • 919 B
JavaScript
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 = null) {
return class AsyncWrapperComponent extends React.PureComponent {
constructor(props) {
super(props);
this.state = { Component: null };
}
componentDidMount() {
if (this.state.Component === null) {
const Component = componentLoader();
this.setState({ Component });
}
}
render() {
const { Component } = this.state;
return Component ? <Component {...this.props}/> : loadingComponent;
}
};
}
//# sourceMappingURL=async.js.map