// 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