UNPKG

775 BJSXView Raw
1// https://gist.github.com/acdlite/a68433004f9d6b4cbc83b5cc3990c194
2
3const React = require('react')
4
5module.exports = (getComponent) =>
6 class AsyncComponent extends React.Component {
7 static Component = null;
8 state = { Component: AsyncComponent.Component };
9
10 componentWillMount() {
11 if (!this.state.Component) {
12 getComponent().then(Component => {
13 AsyncComponent.Component = Component
14 this.setState({ Component })
15 })
16 }
17 }
18 render() {
19 const { Component } = this.state
20 if (Component) {
21 return <Component {...this.props} />
22 }
23 return null
24 }
25 }
26
\No newline at end of file