React中性能优化的方案

  1. shouldComponentUpdate
  • 控制组件自身或子组件是否需要更新,尤其在子组件非常多的情况下,需要进行优化。
  1. PureComponent
  • PureComponent会帮你 比较新Props跟旧的Props,新的State和就的State(值相等,或者对象含有相同的属性、且属性值相等等),决定shouldComponentUpdate 返回true或者false,从而确定要不要呼叫 render function
  • 注意:如果你的state或props【永远都会变】,那PureComponent并不会比较快,因为shallowEqual也需要花时间
posted @ 2022-11-28 16:40  HuangBingQuan  阅读(23)  评论(0编辑  收藏  举报