Skip to content

Instantly share code, notes, and snippets.

@juice49
Created August 28, 2019 15:48
Embed
What would you like to do?
useLazyModule
// 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