Skip to main content

namedLazy

Callable

  • namedLazy<T>(loader: () => Promise<T>, name: keyof T): React.LazyExoticComponent<T[keyof T]>

  • A wrapper around React.lazy that allows you to specify a named export to resolve to.

    @example
    const LazyComponent = namedLazy(() => import('./Component'), 'Component')

    Type parameters

    • T: Record<string, any>

    Parameters

    • loader: () => Promise<T>

      A function that returns a promise that resolves to an object.

    • name: keyof T

      The name of the named export to resolve to.

    Returns React.LazyExoticComponent<T[keyof T]>

    A React.LazyExoticComponent that will resolve to the named export.