Published on

渲染

Authors
  • avatar
    Name
    Reeswell
    Twitter

类组件

  • React.memo 用于对函数组件进行浅层比较,适用于优化组件的渲染性能,特别是当组件的渲染代价较高时,避免不必要的重新渲染。React.memo 适用于优化组渲染性能,特别是当组件的渲染代价较高时。React.memo 接受两个参数,第一个参数 Component 原始组件本身,第二个参数 compare 是一数,第二个参数不存在时,会浅层比较处理 props。基于父组件控制子组件的渲染。

  • PureComponent是基于父组件的props以及组件本身的state浅比较控制组件的渲染。

  • shouldComponentUpdate在组件本身通过新state、新props控制组件的渲染。

执行优先级是: React.memo>shouldComponentUpdate > PureComponent

函数组件

  • 函数组件主要使用useMemo控制组件的渲染。

渲染调优