@lynx-js/react / lazy

函数: 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.

类型参数

类型参数
T extends ComponentType<any>

参数

范围类型描述
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.

返回

LazyExoticComponent<T>

参阅

React Docs

示例

import { lazy } from 'react';

const MarkdownPreview = lazy(() => import('./MarkdownPreview.js'));

定义于

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

除非另有说明,本项目采用知识共享署名 4.0 国际许可协议进行许可,代码示例采用 Apache License 2.0 许可协议进行许可。