[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 behavior of the HOC is similar to what you’d get when using React.PureComponent or shouldComponentUpdate in a React Class Component. However, now with the introduction of React.memo, you can leverage this behavior for React Function Components. The end result is that React will skip rendering the component if the props have not changed and will reuse the last rendered result.
To prevent extra rendering, we can use 'shouldComponentUpdate' in the past, new API 'React.memo' is a high order component which is doing the same things with cleaner API:
const Greeting = React.memo(({ text }) => {
console.log("I'm in Greeting");
return <h3>Hello, {text}!</h3>;
});
If the 'text' prop doesn't change, then the Greeting component won't be re-rendered
[React] Use React.memo with a Function Component to get PureComponent Behavior的更多相关文章
- React源码 memo Fragment StrictMode cloneElement createFactory
1.memo react 16.6 推出的 api ,他的用意是给 function component 也有 PureComponent 这样一个类似的功能,因为我们知道 PureComponent ...
- [React] Preventing extra re-rendering with function component by using React.memo and useCallback
Got the idea form this lesson. Not sure whether it is the ncessary, no othere better way to handle i ...
- error : Hooks can only be called inside of the body of a function component. 依赖包和主包加载多个react 引发冲突问题
1. 结论: 在依赖包和主包的node-modules中,同时install包含react , react-dom 或者react-redux时,跑测试或者启动的时候,显示如下error.当然出现这个 ...
- [React] Cleanly Map Over A Stateless Functional Component with a Higher Order Component
In this lesson we'll create a Higher Order Component (HOC) that takes care of the key property that ...
- React报错之React Hook 'useEffect' is called in function
正文从这开始~ 总览 为了解决错误"React Hook 'useEffect' is called in function that is neither a React function ...
- [React Intl] Use a react-intl Higher Order Component to format messages
In some cases, you might need to pass a string from your intl messages.js file as a prop to a compon ...
- react 使用react-router-dom 在Route对象上component 参数接收的是一个方法而非一个对象
其实对于jsx语法 一直觉的它有点清晰都不是很好,js和html混在一起有点不伦不类的样子,以下是我在使用react中遇到的一个很奇葩的事情 假定你定义了一个component Mine import ...
- [React & Debug] Quick way to debug Stateless component
For example we have the following code: const TodoList = (props) => ( <div className="Tod ...
- 精读《Function Component 入门》
1. 引言 如果你在使用 React 16,可以尝试 Function Component 风格,享受更大的灵活性.但在尝试之前,最好先阅读本文,对 Function Component 的思维模式有 ...
随机推荐
- pssh批量管理服务器
pssh命令是一个python编写可以在多台服务器上执行命令的工具,同时支持拷贝文件,是同类工具中很出色的,类似pdsh,个人认为相对pdsh更为简便,使用必须在各个服务器上配置好密钥认证访问. 1. ...
- 【http】【转发】HTTP访问控制(CORS)
当一个资源从与该资源本身所在的服务器不同的域或端口请求一个资源时,资源会发起一个跨域 HTTP 请求. 比如,站点 http://domain-a.com 的某 HTML 页面通过 <img ...
- Python基础之字符编码,文件操作流与函数
一.字符编码 1.字符编码的发展史 阶段一:现代计算机起源于美国,最早诞生也是基于英文考虑的ASCII ASCII:一个Bytes代表一个字符(英文字符/键盘上的所有其他字符),1Bytes=8bit ...
- .NET重构(九):机房重构验收总结
导读:机房收费系统个人重构版,在寒假前,已经结束了.嗯,这一路的过程,也挺心酸的.结合师傅验收时的指导.建议,对这一段时间的学习,进行一个总结. 一.学习过程 这一阶段的学习,按照师傅给的建议是:由浅 ...
- javascript异常cannot read property xx of null 的错误
一般报这种异常或者错误,是因为试图从null中再读一个属性导致的. 比如:var myAttr=myObj.data.Name; 假如这个时候myObj.data是null,那么再试图读取data的N ...
- 集群高可用之lvs
集群: 随着互联网的发展,大量的客户端的请求,服务器的负载越来越大,单台服务器的负载有限,会导致服务器响应客户端请求的时间越长,甚至产生拒绝服务的情况.目前网站是24小时不间断提供网络服务,仅采用单点 ...
- nginx的详解(二)
查看几个设置 nginx正则表达式常用的是前6个 ^: 匹配字符串的开始位置: $:匹配字符串的结束位置:.*: .匹配任意字符,*匹配数量0到正无穷: \. 斜杠用来转义,\.匹配 . 特殊使用方法 ...
- Luogu【P1130】红牌(DP)
欧拉 本蒟蒻第一个自己想出来的DP题 请移步题目链接 调了半天.i从1到n,j从1到m. f[i][j]表示的是第i道工序在第j个小组办完所花的最短时间. 因为要用到上一个状态,而上一个状态要么是同一 ...
- BZOJ 3227 [Sdoi2008]红黑树(tree) ——贪心 动态规划
首先可以想到一个贪心的方法,然后一层一层的合并. 也可以采用动态规划的方式,为了写起来好写,把点数*2+1,然后发现在本机上跑不过1500的数据. 交上去居然A掉了. 贪心 #include < ...
- POJ 1125 Stockbroker Grapevine【floyd】
很裸的floyd #include<cstdio> #include<string.h> #include<algorithm> #define maxn 201 ...