For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt, and this page is available as Markdown at /next/api/react/Function.lazy.md.
  • English
  • @lynx-js/react / lazy

    Function: lazy()

    function lazy<T>(load: () => Promise<object>): LazyExoticComponent<T>

    Lets you defer loading a component’s code until it is rendered for the first time.

    Type Parameters

    Type Parameter
    T extends ComponentType<any>

    Parameters

    ParameterTypeDescription
    load() => Promise<object>A function that returns a Promise or another thenable (a Promise-like object with a then method). React will not call load until the first time you attempt to render the returned component. After React first calls load, it will wait for it to resolve, and then render the resolved value’s .default as a React component. Both the returned Promise and the Promise’s resolved value will be cached, so React will not call load more than once. If the Promise rejects, React will throw the rejection reason for the nearest Error Boundary to handle.

    Returns

    LazyExoticComponent<T>

    See

    React Docs

    Example

    import { lazy } from 'react';
    
    const MarkdownPreview = lazy(() => import('./MarkdownPreview.js'));

    Defined in

    .pnpm/@types+react@18.3.28/node_modules/@types/react/ts5.0/index.d.ts:1810

    Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.