美文网首页
react native组件渲染时机

react native组件渲染时机

作者: 杨志聪 | 来源:发表于2020-12-10 10:14 被阅读0次

组件(Component)没有通过shouldComponentUpdate来控制渲染时:
1.调用setState一定会触发渲染,不管state的内容是否有改变;
2.父组件渲染时也会触发渲染,不管props的内容是否有改变;

通过shouldComponentUpdate控制渲染后:

  1. 仅shouldComponentUpdate返回true才会触发渲染。

对于纯组件(PureComponent),会自动实现shouldComponentUpdate,对props和state进行浅比较,有不一样的地方返回true,否则返回false。

相关文章

网友评论

      本文标题:react native组件渲染时机

      本文链接:https://www.haomeiwen.com/subject/ukylgktx.html