Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Async Component from Maximilian Schwarzmüller
import React, { Component } from 'react';
const asyncComponent = (importComponent) => {
return class extends Component {
state = {
component: null,
};
componentDidMount() {
importComponent()
.then(cmp => {
this.setState({ component: cmp.default });
});
}
render() {
const Chunk = this.state.component;
return Chunk ? <Chunk {...this.props} /> : null;
}
};
};
export default asyncComponent;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.