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. python基础一 day5 集合

    集合是无序的 增:add()添加进去是无序,不一定是最后面,update()像extend() 删: 没有改,有查,里面的元素是不可变类型 查用for in 交集: 并集: 反交集 叉集: 子集与超集 ...

  2. 图片充当li标签列表标志

    默认情况下,浏览器使用一个黑圆圈作为列表标志,可以用图片取代它: ul {list-style: none} ul li{ background-image: url("img/logo_0 ...

  3. 解决mysql - 1577 问题

    背景:通过navicat连接mysql使用events时报如下错误 登录mysql查询event mysql> use zhk4; Database changed mysql> show ...

  4. UART中RTS、CTS

    RTS (Require ToSend,发送请求)为输出信号,用于指示本设备准备好可接收数据,低电平有效,低电平说明本设备可以接收数据. CTS (Clear ToSend,发送允许)为输入信号,用于 ...

  5. Mac 配置 php-fpm

    Mac 自带 php-fpm,在终端执行 php-fpm,会报如下错误: ERROR: failed to open configuration file '/private/etc/php-fpm. ...

  6. 在ubuntu18.04版本安装vscode

    方式一:图形安装 1. 在ubuntu桌面找到应用中心 2. 在软件中心中,搜索Visual Studio Code 3. 在页面中就可以直接选择安装 方式二:命令安装 1. 从vscode官网下载最 ...

  7. set()集合基本操作

    运用频次:☆☆ set是一个无序且不重复元素集,基本操作如下: 1. 创建set集合,会自动转换成set类型 2. add():添加元素 def add(self, *args, **kwargs): ...

  8. Android Ubuntu 12.04 源码环境搭建

    $ sudo apt-get install git gnupg flex bison gperf build-essential \ zip curl libc6-dev libncurses5-d ...

  9. mysql 分段统计数据

    一个简单的分段统计的问题:student 表{id,name,score} 字段,统计各个分数段的人数.规则:60以下不及格,60-80良,80-100优. SELECT sum(CASE when ...

  10. JS Enter键跳转 控件获得焦点

    //回车跳转 jQuery(document).ready(function () { //$(':input:text:first').focus(); jQuery(':input:enabled ...