dynamic import - react-atomic/reshow GitHub Wiki
Table of Contents
import react, {PureComponent} from 'react';
import 'es6-promise/auto'; // [RESHOW] Need keep if use "new Promise"
import {getDefault} from 'get-object-value';
import {build} from 'react-atomic-molecule';
let FakeComponent;
class ThisComponent extends PureComponent {
state = {isLoad: false}
componentDidMount()
{
import('fake-component').then((objFakeComponent)=>{
FakeComponent = getDefault(objFakeComponent);
this.setState({isLoad: true});
});
}
render()
{
const {isLoad} = this.state;
if (!isLoad) {
return null;
}
return build(FakeComponent); //use build to avoid FakeComponent
}
}
export default ThisComponent;