by jordache · 8y ago · 0 comments
For React, you can use React Loadable (https://github.com/jamiebuilds/react-loadable) that provides a Higher Order Component and Server Side rendering.
class Loader extends React.Component {
state = {
Component: null
};
componentWillMount() {
import('./Component').then(Component => {
this.setState({ Component });
});
}
render() {
const { Component } = this.state;
if (!Component) {
return <div>Loading...</div>;
} else {
return <Component/>;
};
}
}
Might want to add a few lines of error handling for production use, but that is pretty much all you need.https://blog.angularindepth.com/dynamically-loading-componen...