For AI agents: the complete documentation index is available at /next/zh/llms.txt, the full documentation bundle is available at /next/zh/llms-full.txt, and this page is available as Markdown at /next/zh/api/react/Functions/memo.md.
  • 简体中文
  • Function: memo()

    Call Signature

    memo<P extends object>(Component: FunctionComponent<P>, propsAreEqual?: (prevProps: Readonly<P>, nextProps: Readonly<P>) => boolean): NamedExoticComponent<P>

    让你在组件的 props 未变化时跳过重新渲染。

    Type Parameters

    Type Parameter
    P extends object

    Parameters

    ParameterTypeDescription
    ComponentFunctionComponent<P>要进行 memoize 的组件。
    propsAreEqual?(prevProps: Readonly<P>, nextProps: Readonly<P>) => boolean用于判断 props 是否发生变化的函数。

    Returns

    NamedExoticComponent<P>

    See

    React Docs

    Example

    import { memo } from 'react';
    
    const SomeComponent = memo(function SomeComponent(props: { foo: string }) {
      // ...
    });

    Call Signature

    memo<T extends ComponentType<any>>(Component: T, propsAreEqual?: (prevProps: Readonly<ComponentProps<T>>, nextProps: Readonly<ComponentProps<T>>) => boolean): MemoExoticComponent<T>

    让你在组件的 props 未变化时跳过重新渲染。

    Type Parameters

    Type Parameter
    T extends ComponentType<any>

    Parameters

    ParameterTypeDescription
    ComponentT要进行 memoize 的组件。
    propsAreEqual?(prevProps: Readonly<ComponentProps<T>>, nextProps: Readonly<ComponentProps<T>>) => boolean用于判断 props 是否发生变化的函数。

    Returns

    MemoExoticComponent<T>

    See

    React Docs

    Example

    import { memo } from 'react';
    
    const SomeComponent = memo(function SomeComponent(props: { foo: string }) {
      // ...
    });
    除非另有说明,本项目采用知识共享署名 4.0 国际许可协议进行许可,代码示例采用 Apache License 2.0 许可协议进行许可。