Created
          May 24, 2019 19:27 
        
      - 
      
- 
        Save allpro/3151cc9bf5a957e20732ba393c0a373f to your computer and use it in GitHub Desktop. 
    Dynamic Import of a named-export
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | /* | |
| * React.lazy helper for named-export components, instead of default-export | |
| * | |
| * @example const Comp = React.lazy(() => importNamed('./Component', 'Name')) | |
| * | |
| * @param {string} componentPath Path as used normally for import('path') | |
| * @param {string} exportName The name of the export in this component | |
| * @returns {Promise} The promise created by import() | |
| */ | |
| export default (componentPath, exportName) => ( | |
| import(componentPath).then(comp => ({ default: comp[exportName] })) | |
| ) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment