Created
August 28, 2019 15:48
-
-
Save juice49/2b2acd327d6aa6abcfa515ee5677f2c7 to your computer and use it in GitHub Desktop.
useLazyModule
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
// Sadly a full dynamic import is not compatible | |
// with webpack's `import()`. | |
import { useState } from 'react' | |
const useLazyModule = path => { | |
const [ module, setModule ] = useState() | |
;(async () => { | |
const module = await import(path) | |
setModule(module) | |
})() | |
return module | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment