Created
May 4, 2018 15:43
-
-
Save Spyna/368c5149377aa5fe0bc8892d69d19616 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 React from 'react'; | |
import LoadingOverlay from './Loader' | |
export default (loader, props) => ( | |
class AsyncComponent extends React.Component { | |
constructor(props) { | |
super(props); | |
this.Component = null; | |
this.state = { Component: AsyncComponent.Component }; | |
} | |
componentWillMount() { | |
if (!this.state.Component) { | |
loader().then((Component) => { | |
AsyncComponent.Component = Component; | |
this.setState({ Component }); | |
}); | |
} | |
} | |
render() { | |
if (this.state.Component) { | |
return ( | |
<this.state.Component { ...this.props } { ...props } /> | |
) | |
} else { | |
return <LoadingOverlay />; | |
} | |
} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment