内容简介:React 开发团队于2018年10月24日在官方博客宣布了 React 16.6.0。开发团队表示,该版本新增了不少便利的特性,下面我们不妨去了解一下吧! 按照官方的说法,React.memo() 主要是用于函数式组件,作为 PureCompon...
React 开发团队于2018年10月24日在官方博客宣布了 React 16.6.0。开发团队表示,该版本新增了不少便利的特性,下面我们不妨去了解一下吧!
按照官方的说法,React.memo() 主要是用于函数式组件,作为 PureComponent 的替代方案;React.lazy() 则是使用 Suspense 进行代码分割的方法;新增的 contextType 则是作为一种更符合使用习惯的方式用于从类订阅上下文。
React.memo
Class components can bail out from rendering when their input props are the same using PureComponent or shouldComponentUpdate. Now you can do the same with function components by wrapping them in React.memo.
const MyComponent = React.memo(function MyComponent(props) {
/* only rerenders if props change */
});React.lazy: Code-Splitting with Suspense
You may have seen Dan’s talk about React Suspense at JSConf Iceland. Now you can use the Suspense component to do code-splitting by wrapping a dynamic import in a call to React.lazy().
import React, {lazy, Suspense} from 'react';
const OtherComponent = lazy(() => import('./OtherComponent'));
function MyComponent() {
return (
<Suspense fallback={<div>Loading...</div>}>
<OtherComponent />
</Suspense>
);
}The Suspense component will also allow library authors to start building data fetching with Suspense support in the future.
Note: This feature is not yet available for server-side rendering. Suspense support will be added in a later release.
【声明】文章转载自:开源中国社区 [http://www.oschina.net]
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- [译] PowerShell Core 6.0 的新增特性
- Elixir 1.9.0 发布,新增“release”特性
- Elixir 1.9.0 发布,新增“release”特性
- PostgreSQL 10 首个测试版发布,新增特性一览
- Corestart 2.0:.NET Core 2.0 新增特性
- PostgreSQL 10 首个测试版发布,新增特性一览
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Linux程序设计
Neil Matthew、Richard Stones / 陈健、宋健建 / 人民邮电出版社 / 201005 / 99.00元
时至今日,Linux系统已经从一个个人作品发展为可以用于各种关键任务的成熟、高效和稳定的操作系统,因为具备跨平台、开源、支持众多应用软件和网络协议等优点,它得到了各大主流软硬件厂商的支持,也成为广大程序设计人员理想的开发平台。 本书是Linux程序设计领域的经典名著,以简单易懂、内容全面和示例丰富而受到广泛好评。中文版前两版出版后,在国内的Linux爱好者和程序员中也引起了强烈反响,这一热潮......一起来看看 《Linux程序设计》 这本书的介绍吧!