[英]React PureComponent can be slower than Component? How?
I'm referring to a post by Dan Abramov stating: 我指的是Dan Abramov的一则帖子:
PSA: React.PureComponent can make your app slower if you use it everywhere.
PSA:如果在任何地方使用它,React.PureComponent都会使您的应用程序变慢。
(Dan's tweet on the topic) (Dan在该主题上的推文)
Can someone elaborate on this? 有人可以详细说明吗? Thank you.
谢谢。
PureComponent implements a shouldComponentUpdate with shallow comparison of component state and props. PureComponent通过对组件状态和属性进行浅比较来实现一个shouldComponentUpdate。 It compares the currentProps against nextProps (similarly for state) and only if there is a change, the render method is invoked.
它将currentProps与nextProps(状态类似)进行比较,并且仅当发生更改时,才会调用render方法。 The additional overhead of this comparison would definitely slow down the application especially if your component and state are heavy.
这种比较的额外开销肯定会减慢应用程序的速度,尤其是在您的组件和状态繁重的情况下。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.