Last active
October 29, 2018 07:04
-
-
Save mhmdAljefri/3b6760026049821b45180289d594ccb4 to your computer and use it in GitHub Desktop.
This file contains 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' | |
const codeSplittingHoc = impoertComponent => | |
class componentName extends React.Component { | |
state = { | |
component: null // default state for component | |
} | |
async componentDidMount() { | |
const { default: component } = await impoertComponent(); // import default from function and assign it to component | |
this.setState({ component }) // set component module component as state to use it on render() | |
}; | |
render() { | |
const { component: Component } = this.state; // Capitlize component to use it as React Component | |
return ( | |
Component ? | |
<Component /> : | |
null {* do what you want @here *} | |
) | |
} | |
} | |
export default codeSplittingHoc; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment