Answer the question
In order to leave comments, you need to log in
How to disable splitting in webpack?
there is a HOC - component:
import React, {Component} from "react";
function asyncComponent(getComponent) {
class AsyncComponent extends Component {
constructor(props) {
super(props);
this.state = {Component: AsyncComponent.Component};
}
componentWillMount() {
if ( !this.state.Component ) {
getComponent().then(Component => {
AsyncComponent.Component = Component;
this.setState({Component})
})
}
}
render() {
const {Component} = this.state;
if (Component)
return <Component {...this.props} />;
return null;
}
}
return AsyncComponent;
}
export default asyncComponent;
import asyncComponent from '../AsyncComponent';
const Account = asyncComponent(() =>
import('../layouts/Account').then(module => module.default)
);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question