[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 的思维模式有 ...
随机推荐
- vs进行C#编程中常用的几个快捷键
(1)输入svm然后按Tab键会生成Main函数: (2)Ctrl +k+s 三个键一起按,会调出代码段:选中多行后,然后按以上三个快捷键,输入需要使用的代码段,按下Tab,代码段会自动包括选中代码. ...
- html,css样式错误总结
a元素不能嵌套a元素 a元素嵌套a元素会使a元素闭合出现混乱,导致浏览器识别出多个a元素.
- [转]python开发_shelve_完整版
''' python中的shelve模块,可以提供一些简单的数据操作 他和python中的dbm很相似. 区别如下: 都是以键值对的形式保存数据,不过在shelve模块中, key必须为字符串,而值可 ...
- Mac下的Eclipse不能记住工作空间问题
每次启动eclipse都要选择工作空间,即使你勾选了"选择这个作为默认"也不行. Eclipse版本 4.5, mac os版本10.12 找到这个目录下的config.ini文件 ...
- python jieba包用法总结
# coding: utf-8 # ###jieba特性介绍 # 支持三种分词模式: # 精确模式,试图将句子最精确地切开,适合文本分析: # 全模式,把句子中所有的可以成词的词语都扫描出来, 速度非 ...
- HDU 5441 Travel
Travel Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Descrip ...
- ubuntu 转换图片格式的方法(sam2p, imagemagick)
(1) 终端:sudo apt-get install sam2p sam2p [原图片名.格式] [目标图片名.格式] 即可在同一目录下生成目标图片格式 (2) 终端: sudo apt-get i ...
- 【原】缓存之 HttpRuntime.Cache
1.HttpRuntime.Cache HttpRuntime.Cache 相当于就是一个缓存具体实现类,这个类虽然被放在了 System.Web 命名空间下了.但是非 Web 应用也是可以拿来用的. ...
- Charlie's Change(完全背包记录路径)
Charlie is a driver of Advanced Cargo Movement, Ltd. Charlie drives a lot and so he often buys coffe ...
- 【Ts 3】Nginx的Http(图片)服务器配置+ftp上传使用说明
在前两篇博客中提到了搭建Nginx和Ftp服务器,在本篇博客,主要是介绍Nginx的配置文件的使用,怎样修改配置文件使其成为一个图片服务器. 一.Nginx图片服务器配置 <span style ...