Last active
September 28, 2018 09:38
-
-
Save jpgorman/352265a3b4c23d19898c208d386bc494 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from "react"; | |
export class LazyLoadModule extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
module: null | |
}; | |
} | |
// after the initial render, wait for module to load | |
async componentDidMount() { | |
const { resolve } = this.props; | |
const { default: module } = await resolve(); | |
this.setState({ module }); | |
} | |
render() { | |
const { module } = this.state; | |
if (!module) return <div>Loading module...</div>; | |
if (module.view) return React.createElement(module.view); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment