dynamic import - react-atomic/reshow GitHub Wiki

Table of Contents

dynamic import sample

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;

Code change

Fixed Module build failed: SyntaxError: 'import' and 'export' may only appear at the top level

Official documentation

Webpack magic comment

⚠️ **GitHub.com Fallback** ⚠️