Skip to content

Instantly share code, notes, and snippets.

@dance2die
Created December 4, 2017 01:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dance2die/bb657a5c14121429cabbeee4c922860d to your computer and use it in GitHub Desktop.
Save dance2die/bb657a5c14121429cabbeee4c922860d to your computer and use it in GitHub Desktop.
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