Skip to content

Instantly share code, notes, and snippets.

@allpro
allpro / importNamed.js
Created May 24, 2019 19:27
Dynamic Import of a named-export
/*
* 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) => (