Created
December 4, 2017 01:56
-
-
Save dance2die/bb657a5c14121429cabbeee4c922860d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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