use suspense

This commit is contained in:
MapleLeaf
2021-12-31 17:09:09 -06:00
committed by Darius
parent 9afb8e47d2
commit d2cadb536d
8 changed files with 72 additions and 98 deletions

View File

@@ -0,0 +1,11 @@
import { lazy } from "react"
export function lazyNamed<
Key extends string,
Component extends React.ComponentType,
>(key: Key, loadModule: () => Promise<Record<Key, Component>>) {
return lazy<Component>(async () => {
const mod = await loadModule()
return { default: mod[key] }
})
}