In this lesson, you will learn how to use PureComponent in React to reduce the number of times your component re-renders.

This works because PureComponent implements a shallow comparison for us by default in shouldComponentUpdate() , saving us time and reducing the complexity of our components. Its important to note that the comparison is shallow, meaning that if you are updating an object with nested values the component will not re-render as React has not noticed a change.

The same, if you pass a prop as a function reference, it will not cause re-render, but is you pass a anonymous arrow function which means it will create a new function every time, then it will cuase re-render.

 handleChange = e => {
const { name, value } = e.target;
this.setState({ [name]: value });
}; // pass a function
<Counter onChange={this.handleChange} /> // vs pass a arrow function
<Counter onChange={() => console.log('this will cause re-render')} />

[React] PureComponent in React的更多相关文章

  1. React.Component 与 React.PureComponent(React之性能优化)

    前言 先说说 shouldComponentUpdate 提起React.PureComponent,我们还要从一个生命周期函数 shouldComponentUpdate 说起,从函数名字我们就能看 ...

  2. React.Component 和 React.PureComponent 、React.memo 的区别

    一 结论 React.Component 是没有做任何渲染优化的,但凡调用this.setState 就会执行render的刷新操作. React.PureComponent 是继承自Componen ...

  3. React PureComponent All In One

    React PureComponent All In One import React, { // useState, // useEffect, // Component, PureComponen ...

  4. [React] React.PureComponent

    React.PureComponent is similar to React.Component. The difference between them is that React.Compone ...

  5. React源码 React.Component

    React中最重要的就是组件,写的更多的组件都是继承至 React.Component .大部分同学可能都会认为 Component 这个base class 给我们提供了各种各样的功能.他帮助我们去 ...

  6. react系列从零开始-react介绍

    react算是目前最火的js MVC框架了,写一个react系列的博客,顺便回忆一下react的基础知识,新入门前端的小白,可以持续关注,我会从零开始教大家用react开发一个完整的项目,也会涉及到w ...

  7. [react] 细数 React 的原罪

    Props & onChange 的原罪 .「props & onChange 接口规范」它不是一个典型的「程序接口规范」. 当你拿到一个可视组件的 ref,却没有类似 setProp ...

  8. React Native & react-native-web-player & React Native for Web

    React Native & react-native-web-player & React Native for Web https://github.com/dabbott/rea ...

  9. React笔记:React基础(2)

    1. JSX JSX是一种拥有描述UI的JavaScript扩展语法,React使用这种语法描述组件的UI. 1.1 基本语法 JSX可以嵌套多个HTML标签,可以使用大部分符号HTML规范的属性. ...

随机推荐

  1. Microsoft Windows Server DHCP

    Microsoft Windows Server DHCP DHCP IP地址第一个来源是DHCP服务器,第二个来源是PPP点对点协议(ADSL为PPPOE);DHCP是Dynamic Host Co ...

  2. 剑指Offer(Python)

    014-链表中倒数第k个结点 用快慢指针:p2比p1先走到k:间隔了k-1)步,然后再一起走,当p2为最后一个时,p1就为倒数第k个数 class ListNode: def __init__(sel ...

  3. jquery点击tr换背景颜色

    jquery点击tr换tr的背景颜色,table的id为db-list1jQuery(function() { jQuery("#db-list1 tr").click( func ...

  4. 连接mysql 2003 Can't connect to Mysql on 'xxx'(10061)

    备份 cp /etc/mysql/my.cnf /etc/mysql/my.cnf.bak 修改 vim /etc/mysql/my.cnf 在[mysqld]下修改为bind-address=0.0 ...

  5. tomcat域名配置

    修改tomcat目录下的web配置文件 vim conf/server.xml 在host标签内添加 <Context path="bbs" docBase="/a ...

  6. Python处理PDF-通过关键词定位-截取PDF中的图表

    起因: 因为个人原因, 这些天了解了一下Python处理PDF的方法. 首先是PDF转txt, 这个方法比较多, 这里就不再赘述, 主要聊一下PDF中的图片获取. 这里用我自己的例子, 不过具体情况还 ...

  7. python中的函数的分类

    函数的种类 传参的基本要求 默认参数 *args 关键字参数 **kwargs 普通函数 带参数 默认参数 def text(a,b=2) print("haha") print( ...

  8. solr中的Tokenizer Filter

    Tokenizer Tokenizer 的工作是将文本流分解为令牌,其中每个令牌(通常)是文本中字符的子序列.分析器知道它配置的字段,但 tokenizer 不是.Tokenizers 从字符流(Re ...

  9. POJ 1979 Red and Black (DFS)

    Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...

  10. oo的一些概念

    http://docs.kissyui.com/5.0/guides/base/oo.html JavaScript 语言自成体系,自有一套代码重用的模式,这些常见的代码重用模式可以在<Java ...