实验
线上demo: https://codesandbox.io/s/4j3k…
首次进页面render结果
state 变化后的结果
结果总结
组件 | 绑定方式 | 结果 (首次 render 次数) | 不涉及当前组件组件父组件state变化后render次数 |
---|---|---|---|
class组件 | 非箭头函数函数 | 1次 | 1次 |
class组件 | 箭头函数函数 | 1次 | 1次 |
pureclass组件 | 箭头函数 | 1次 | 1次 |
pureclass组件 | 非箭头函数 | 1次 | 0次 |
结论
非匿名函数 + pureComponent 组件能优化性能