1 |
|
2 |
|
3 | const React = require('react')
|
4 |
|
5 | module.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 |