Skip to content

Instantly share code, notes, and snippets.

@mihir0x69
Last active July 8, 2017 06:19
Show Gist options
  • Save mihir0x69/aef3058a0dad5abb7663577539d6a232 to your computer and use it in GitHub Desktop.
Save mihir0x69/aef3058a0dad5abb7663577539d6a232 to your computer and use it in GitHub Desktop.
Using es6 import
const getModule = (cb) => (componentModule, submodule) => {
cb(null, componentModule.default)
};
const logError = (err) => {
console.error('Dynamic page loading failed', err);
};
getComponent(location, cb) {
const importedModule = Promise.all([
import('./MyComponent.react.js')
])
const renderRoute = getModule(cb)
importedModule.then(([component]) => {
renderRoute(component)
})
importedModule.catch(logError)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment