React PureComponent All In One


import React, {
// useState,
// useEffect,
// Component,
PureComponent,
} from "react"; // import "./style.css"; // pccs, PureComponent Class With Constructor
class App extends PureComponent {
constructor(props) {
super(props);
this.state = {};
}
render() {
const {
id,
name,
} = props;
return (
<>
<div>
<p>id = {id || 2020}</p>
<p>name = {name || xgqfrms}</p>
</div>
</>
);
}
} export default App; // pcs, PureComponent Class
class PCSApp extends PureComponent {
state = { }
render() {
return (
<>
<p>Hello, React Pure Component!</p>
</>
);
}
} // export default PCSApp; // pcsf, PureComponent Class FlowType // type P = {
// str: string,
// }; // type S = {
// int: number,
// }; // class PCSFApp extends PureComponent<P, S> {
// state = { }
// render() {
// return (
// <>
// <p>pcsf, PureComponent Class FlowType</p>
// </>
// );
// }
// } // export default PCSFApp;

PureComponent

https://reactjs.org/docs/react-api.html

UMD (CJS, global, AMD, CMD) + ESM

源码怎么实现的?

  1. ES6

React.Component

React.PureComponent

JSX, React.createElement() 语法糖

https://reactjs.org/docs/introducing-jsx.html

  1. ES5

create-react-class

https://reactjs.org/docs/react-without-es6.html

createElement()

createFactory()

https://reactjs.org/docs/react-without-jsx.html

Class Components vs Function Components (React Hooks)

https://reactjs.org/tutorial/tutorial.html

  1. Class Components

https://reactjs.org/docs/react-component.html

React.PureComponent 浅比较

https://reactjs.org/docs/react-component.html#shouldcomponentupdate

https://reactjs.org/docs/react-component.html#forceupdate

immutable objects 深比较

https://facebook.github.io/immutable-js/

React Lifecycle

很少使用到

shouldComponentUpdate(nextProps, nextState)

https://reactjs.org/docs/react-component.html#rarely-used-lifecycle-methods

refs

https://reactjs.org/docs/components-and-props.html

https://reactjs.org/docs/state-and-lifecycle.html

https://reactjs.org/docs/composition-vs-inheritance.html



xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


React PureComponent All In One的更多相关文章

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

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

  2. [React] React.PureComponent

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

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

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

  4. [React] PureComponent in React

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

  5. 【react】---pureComponent的理解

    一.pureComponent的理解  pureComponent表示一个纯组件,可以用来优化react程序.减少render函数渲染的次数.提高性能 pureComponent进行的是浅比较,也就是 ...

  6. React性能优化 PureComponent

    为什么使用? React15.3中新加了一个 PureComponent 类,顾名思义, pure 是纯的意思, PureComponent 也就是纯组件,取代其前身 PureRenderMixin  ...

  7. [React] Use React.memo with a Function Component to get PureComponent Behavior

    A new Higher Order Component (HOC) was recently released in React v16.6.0 called React.memo. This be ...

  8. react 中的 PureComponent

    React.PureComponent最重要的一个用处就是优化React应用,因为它减少了应用中的渲染次数,所以对性能的提升是非常可观的. 原理:在普通的 componnet 组件中,shouldCo ...

  9. React性能优化之PureComponent 和 memo使用分析

    前言 关于react性能优化,在react 16这个版本,官方推出fiber,在框架层面优化了react性能上面的问题.由于这个太过于庞大,我们今天围绕子自组件更新策略,从两个及其微小的方面来谈rea ...

随机推荐

  1. DHCP中继配置

    (三台都需要关闭防火墙 前两台需要安装dhcp ) 第一台linux(vmnet2)(192.168.1.1) vim /etc/sysconfig/network-scripts/ifcfg-ens ...

  2. Bitter.Core系列二:Bitter ORM NETCORE ORM 全网最粗暴简单易用高性能的 NETCore ORM 之数据库连接

    Bitter.Core NETCore 相当的简单易用,下面附上使用示例: 数据中连接:请在你的NETCORE 项目中 创建:Bitter.json 配置文件,然后追加如下配置内容: MSSQL 连接 ...

  3. Building a high performance JSON parser

    Building a high performance JSON parser https://dave.cheney.net/high-performance-json.html

  4. monitor a local unix domain socket like tcpdump

    Can I monitor a local unix domain socket like tcpdump? - Super User https://superuser.com/questions/ ...

  5. Supporting Multiple Versions of WebSocket Protocol 支持多版本WebSocket协议

    https://tools.ietf.org/html/rfc6455#section-4.4 4.4. Supporting Multiple Versions of WebSocket Proto ...

  6. Microsoft Windows的消息循环

    https://zh.wikipedia.org/wiki/Microsoft_Windows的訊息迴圈 微软视窗操作系统是以事件驱动做为程序设计的基础.程序的线程会从操作系统获取消息.应用程序会不断 ...

  7. <script>元素

    简介 向HTML页面中插入JavaScript的主要方法,就是使用'<'script'>'元素. 标签的位置 现代Web应用程序一般都把全部的JavaScript饮用放在'<'bod ...

  8. Shiro中Subject对象的创建与绑定流程分析

    我们在平常使用Shrio进行身份认证时,经常通过获取Subject 对象中保存的Session.Principal等信息,来获取认证用户的信息,也就是说Shiro会把认证后的用户信息保存在Subjec ...

  9. C# 给Word不同页面设置不同背景

    给Word文档设置背景时,通常只能针对整篇文档设置统一的背景,如果需要对某些页面单独设置背景,则需要通过另外的方式来实现.本文通过C# 程序代码演示如何来实现.并附VB.NET代码作参考. 思路:通过 ...

  10. 使用Selenium截取网页上的图片

    前言 同样是为了刷课,没想到工作后依然和大学一样逃脱不了需要刷网课的命运-- 正文 直接说干货了,截取图片,需要截取的图片是什么图片大家都懂(说的就是你,验证码),其他图片的话不需要截取,直接拿到地址 ...