SUNYIMIN / react-review

react
2 stars 0 forks source link

什么是 Pure Components? #4

Open SUNYIMIN opened 4 years ago

SUNYIMIN commented 4 years ago

Pure Componentsu与react Component基本一样,Pure Components内部封装了shouldComponentUpdate函数,会对组件的状态和属性的变更进行浅比较,如果变更有差异,则返回true,会对组件进行重新的渲染,如果变更没有差异,则返回false,对组件不进行重新的渲染。react Component组件中如果不写shouldComponentUpdate函数,则都默认返回true,对组件进行重新渲染。为什么是进行浅比较?进行深比较所消耗的性能开销可能比直接运行render还要大