PureComponent中是在shouldComponentUpdate中进行了一层浅比较
使用PureComponent能够在组件再次渲染时避免很多无用的计算,在实际使用中用PureComponent会存在什么问题或者坑吗?
按照我的理解,只要满足immutable应该是不会出问题的
PureComponent中是在shouldComponentUpdate中进行了一层浅比较
使用PureComponent能够在组件再次渲染时避免很多无用的计算,在实际使用中用PureComponent会存在什么问题或者坑吗?
按照我的理解,只要满足immutable应该是不会出问题的
13 回答13k 阅读
7 回答2.2k 阅读
3 回答1.3k 阅读✓ 已解决
6 回答1.3k 阅读✓ 已解决
2 回答1.4k 阅读✓ 已解决
3 回答1.3k 阅读✓ 已解决
4 回答1.7k 阅读
是的,只要满足
immutable
就不会出问题,所以适合搭配immutable.js
使用...坑的话,你能想到
immutable
和shouldComponentUpdate
浅比较,大概也能想到了,就是state
或者props
是引用类型时,如果直接改变内部的属性,而不是返回一个新的引用,就会有问题。。例如:
因为
foo
就是arr
, 所以浅比较时,会返回false
, 不会重新render