lazy
Wrapper around React.lazy that works also with component without default export and with possibility to execute a function before and after component loading.
Types
LazyProps
@templateT - TheComponentTypeexported by the dynamic module.
Parameters accepted by lazy.
| Property | Type | Required | Description |
|---|---|---|---|
load | () => Promise<{ [k: string]: T }> | ✓ | A dynamic import factory that returns a Promise resolving to a module object whose values are ComponentType instances (e.g. () => import("./MyComponent")). The resolved component is cached after the first load. |
opts | { componentName?: string; beforeLoad?: () => void; afterLoad?: () => void; } | Optional configuration. |
LazyResult
@templateT - TheComponentTypeexported by the dynamic module.
Return value of lazy.
A {@link LazyExoticComponent} wrapping the resolved component T, compatible with <Suspense> for code-splitting.
ts
export type LazyResult<T extends ComponentType<unknown>> = LazyExoticComponent<T>;