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. ES6 export default 和 export 的区别

    export default 和 export 区别: 1.export与export default均可用于导出常量.函数.文件.模块等 2.你可以在其它文件或模块中通过import+(常量 | 函 ...

  2. CreateProcess Access violation(越界访问)

    https://stackoverflow.com/questions/11339186/createprocess-fails-with-an-access-violation My aim is ...

  3. 搜索 || DFS || UOJ 146 信息传递

    DFS+回溯 找最小环 每个人知道自己的生日,每次把自己知道的生日告诉固定的一个人,问最少多少次之后能从别人口中听到自己的生日 找一个最小环 #include <iostream> #in ...

  4. 利用条件运算符的嵌套来完成此题: 学习成绩>= 90分的同学用A表示, 60-89分之间的用B表示, 60分以下的用C表示。

    题目:利用条件运算符的嵌套来完成此题: 学习成绩>= 90分的同学用A表示, 60-89分之间的用B表示, 60分以下的用C表示. 程序分析:(a> b)?a:b这是条件运算符的基本例子. ...

  5. ios之sqllite3简单使用

    SQLite3是嵌入在iOS中的关系型数据库,对于存储大规模的数据很有效.SQLite3使得不必将每个对象都加到内存中. 基本操作: (1)打开或者创建数据库 sqlite3 *database; i ...

  6. 【03】使用 Firebug 调试 JavaScript

    [03] 使用 Firebug 调试 JavaScript 描述 Firebug是一个非常强大的工具,可以帮助您发现代码发现错误的错误并解决错误. 在此我们使用Firebug来处理Javascript ...

  7. CactiI表结构和数据被动获取

    cacti我们也用了很久了,但是它的表结构一直都没有去关心过,得空抽了半个晚上的时间,把它的库表结构大概看了下,某些字段的含义跟大家分享下:cacti的数据都是存放在rrdtool中的,数据库存放的其 ...

  8. waiting TTFB 时间优化

    百度百科解释:获取在接收到响应的首字节前花费的毫秒数. 根据chrome浏览器,具体请求链接的这个时间,对反应慢的页面进行优化.

  9. 什么是Etcd?

    文章大部分引至:http://jolestar.com/etcd-architecture/ Etcd 按照官方介绍 Etcd is a distributed, consistent key-val ...

  10. php中configure报错问题

    https://blog.csdn.net/dodott/article/details/49664379 PHP的安装虽然有时候很简单,可是如果应用一多,我们安装起来就很头痛了!出错最多的就是安装P ...