Created
December 4, 2017 02:13
-
-
Save dance2die/38b39a57eecb9efd86ec8220bda5081b 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
addView = async viewName => { | |
// Don't load more than once. | |
if (this.state.loadedComponents.includes(viewName)) return; | |
console.log(`Loading ${viewName} view...`); | |
import(`./views/${viewName}.js`) | |
.then(Component => { | |
this.setState({ | |
loadedComponents: this.state.loadedComponents.concat(viewName), | |
components: this.state.components.concat( | |
<Component.default | |
key={shortid.generate()} | |
data={this.props.data} | |
/> | |
) | |
}); | |
}) | |
.catch(error => { | |
this.setState({ | |
loadedComponents: this.state.loadedComponents.concat(viewName), | |
components: this.state.components.concat( | |
<NullView key={shortid.generate()} /> | |
) | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment