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的更多相关文章

  1. React源码 memo Fragment StrictMode cloneElement createFactory

    1.memo react 16.6 推出的 api ,他的用意是给 function component 也有 PureComponent 这样一个类似的功能,因为我们知道 PureComponent ...

  2. [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 ...

  3. 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.当然出现这个 ...

  4. [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 ...

  5. React报错之React Hook 'useEffect' is called in function

    正文从这开始~ 总览 为了解决错误"React Hook 'useEffect' is called in function that is neither a React function ...

  6. [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 ...

  7. react 使用react-router-dom 在Route对象上component 参数接收的是一个方法而非一个对象

    其实对于jsx语法 一直觉的它有点清晰都不是很好,js和html混在一起有点不伦不类的样子,以下是我在使用react中遇到的一个很奇葩的事情 假定你定义了一个component Mine import ...

  8. [React & Debug] Quick way to debug Stateless component

    For example we have the following code: const TodoList = (props) => ( <div className="Tod ...

  9. 精读《Function Component 入门》

    1. 引言 如果你在使用 React 16,可以尝试 Function Component 风格,享受更大的灵活性.但在尝试之前,最好先阅读本文,对 Function Component 的思维模式有 ...

随机推荐

  1. dom4j 常用操作

    package com.wanbang.wbyyb.common.util; import com.alibaba.fastjson.JSONObject; import com.wanbang.wb ...

  2. DNS 网关 子网掩码介绍

    DNS DNS(Domain Name System,域名系统),因特网上作为域名和IP地址相互映射的一个分布式数据库,能够使用户更方便的访问互联网,而不用去记住能够被机器直接读取的IP数串.通过主机 ...

  3. 在 shell中, 我們可用 $0, $1, $2, $3 ... 這樣的变量分別提取命令行中变量

    代码: script_name parameter1 parameter2 parameter3 ...我們很容易就能猜出 $0 就是代表 shell script 名称(路径)本身,而 $1 就是其 ...

  4. 链式链表的C风格实现

    头文件: #ifndef _LINKLIST_H_ #define _LINKLIST_H_ typedef void LinkList; //将数据的类型分离,相当于句柄 //只是一个小节点 包含着 ...

  5. windows liver writer下载地址

    wlsetup-all.exe 链接:http://pan.baidu.com/s/1bo9pm7X 密码:zchb wlsetup-all简体版.exe 链接:http://pan.baidu.co ...

  6. 【LeetCode】Roman to Integer(罗马数字转整数)

    这道题是LeetCode里的第13道题. 题目说明: 罗马数字包含以下七种字符: I, V, X, L,C,D 和 M. 字符 数值 I 1 V 5 X 10 L 50 C 100 D 500 M 1 ...

  7. python pdb模块

    参考文件http://pythonconquerstheuniverse.wordpress.com/category/Python-debugger/ 翻译不是一一对应 Debug功能对于devel ...

  8. TOJ 4244: Sum

    4244: Sum   Time Limit(Common/Java):3000MS/9000MS     Memory Limit:65536KByteTotal Submit: 63       ...

  9. 【Go】错误处理

    · error类型是一个接口类型,也是一个Go语言的内建类型.在这个接口类型的声明中只包含了一个方法Error.这个方法不接受任何参数,但是会返回一个string类型的结果.它的作用是返回错误信息的字 ...

  10. 【字符串】BNUOJ 52781 Book Borders

    https://www.bnuoj.com/v3/problem_show.php?pid=52781 [AC] #include<bits/stdc++.h> using namespa ...