Skip to content

Instantly share code, notes, and snippets.

@MicroBenz
Created July 6, 2018 08:20
Show Gist options
  • Save MicroBenz/c9797a3c3dd5e2aaf3a6cf773c02abdb to your computer and use it in GitHub Desktop.
Save MicroBenz/c9797a3c3dd5e2aaf3a6cf773c02abdb to your computer and use it in GitHub Desktop.
React Code Splitting
class MyComponent extends React.Component {
state = {
Bar: null
};
componentWillMount() {
import('./components/Bar').then(Bar => {
this.setState({ Bar });
});
}
render() {
let {Bar} = this.state;
if (!Bar) {
return <div>Loading...</div>;
} else {
return <Bar/>;
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment