Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
"addComponent" in App.js under "React Dynamic Component" project
addComponent = async type => {
console.log(`Loading ${type} component...`);
import(`./components/${type}.js`)
.then(component =>
this.setState({
components: this.state.components.concat(component.default)
})
)
.catch(error => {
console.error(`"${type}" not yet supported`);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment