Last active
July 8, 2017 06:19
-
-
Save mihir0x69/aef3058a0dad5abb7663577539d6a232 to your computer and use it in GitHub Desktop.
Using es6 import
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
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