Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
async componentDidMount() {
const { events } = this.props;
events.map(async event => await this.addComponent(event));
}
addComponent = async event => {
const { type } = event;
console.log(`Loading ${type} component...`);
import(`./github_components/${type}.js`)
.then(Component =>
this.setState({
components: this.state.components.concat(
<Component.default key={shortid.generate()} {...event} />
)
})
)
.catch(error => {
// Add an empty component for loading message
this.setState({
components: this.state.components.concat(
<NullComponent key={shortid.generate()} />
)
})
console.error(`"${type}" not yet supported`);
});
};
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.