Skip to content

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

  • @template T - The ComponentType exported by the dynamic module.

Parameters accepted by lazy.

PropertyTypeRequiredDescription
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. () =&gt; import("./MyComponent")). The resolved component is cached after the first load.
opts{ componentName?: string; beforeLoad?: () => void; afterLoad?: () => void; }Optional configuration.

LazyResult

  • @template T - The ComponentType exported 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>;

Released under the MIT License.