[React] PureComponent in React
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的更多相关文章
- React.Component 与 React.PureComponent(React之性能优化)
前言 先说说 shouldComponentUpdate 提起React.PureComponent,我们还要从一个生命周期函数 shouldComponentUpdate 说起,从函数名字我们就能看 ...
- React.Component 和 React.PureComponent 、React.memo 的区别
一 结论 React.Component 是没有做任何渲染优化的,但凡调用this.setState 就会执行render的刷新操作. React.PureComponent 是继承自Componen ...
- React PureComponent All In One
React PureComponent All In One import React, { // useState, // useEffect, // Component, PureComponen ...
- [React] React.PureComponent
React.PureComponent is similar to React.Component. The difference between them is that React.Compone ...
- React源码 React.Component
React中最重要的就是组件,写的更多的组件都是继承至 React.Component .大部分同学可能都会认为 Component 这个base class 给我们提供了各种各样的功能.他帮助我们去 ...
- react系列从零开始-react介绍
react算是目前最火的js MVC框架了,写一个react系列的博客,顺便回忆一下react的基础知识,新入门前端的小白,可以持续关注,我会从零开始教大家用react开发一个完整的项目,也会涉及到w ...
- [react] 细数 React 的原罪
Props & onChange 的原罪 .「props & onChange 接口规范」它不是一个典型的「程序接口规范」. 当你拿到一个可视组件的 ref,却没有类似 setProp ...
- 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 ...
- React笔记:React基础(2)
1. JSX JSX是一种拥有描述UI的JavaScript扩展语法,React使用这种语法描述组件的UI. 1.1 基本语法 JSX可以嵌套多个HTML标签,可以使用大部分符号HTML规范的属性. ...
随机推荐
- Vue.js系列之vue-router(上) (转载自向朔1992)
概述 Vue非常适用于实践单页面应用程序也就是平时大家说的比较多的SPA(single page application),这点应该了解过Vue的应该都知道吧.一般的单页面应用是基于路由或页面之间的链 ...
- golang 解析json 动态数组
#cat file { "Bangalore_City": "35_Temperature", "NewYork_City": " ...
- 配置maven报错 the java_home environment variable is not defined correctly ......
the java_home environment variable is not defined correctly This environment variable is needed to r ...
- The following signatures couldn't be verified because the public key is not available: NO_PUBKEY XXXX
reference apt-key adv --recv-keys --keyserver keyserver.ubuntu.com XXXXXX apt-get update
- 01Ping程序的设计
1.Ping程序设计具体设计任务 1.1 实验目的 PING程序是我们使用的比较多的用于测试网络连通性的程序.PING程序基于ICMP,使用ICMP的回送请求和回送应答来工作.由计算机网络课程知道,I ...
- Oracle 11G RAC For ASM 利用RMAN COPY进行存储迁移
转载请注明出处 一.需求背景 客户数据库存储空间接近存满,需购置一台新的存储,进行数据迁移,客户允许少量停机时间. 二.实施方法讨论 利用ASM rebalance 进行迁移 可以实现0宕机进行迁移, ...
- log4j 、logback 以及slf4j三者之间的关系
在项目的开发中由于对于log4j.logback以及slf4j之间的关系和相关的知识不能清晰掌握,在业余时间进行记录. 1.三者之间的关系 1) 简答的讲就是slf4j是一系列的日志接口,而log4j ...
- pytest以函数形式的测试用例
from __future__ import print_function#pytest以函数形式形成测试用例def setup_module(module): print('\nsetup_modu ...
- 04 Beautiful Soup
Beautiful Soup 简介 简单来说,Beautiful Soup是python的一个库,最主要的功能是从网页抓取数据.官方解释如下: ''' Beautiful Soup提供一些简单的.py ...
- int内部方法释义
python基本数据类型包括:int.str.list.tuple.dict.bool.set(),一切事物都是对象,对象由类创建 1. bit_length:返回数字占用的二进制最小位数 def b ...