Skip to Content
React学习手册
book

React学习手册

by Alex Banks, Eve Porcello
December 2017
Intermediate to advanced
329 pages
6h 9m
Chinese
China Electric Power Press Ltd.
Content preview from React学习手册
组件扩展
171
State
。当
State
被折叠了,我们只能看到一个按钮。当它被展开时,我们可以看到一
个按钮和一个包含隐藏内容的
div
高阶组件是一种极佳的功能复用方式,并且能够将组件
State
和生命周期管理的细节封
装起来。它允许用户构建更多无状态函数式组件,以便可以一心一意地管理
UI
React
之外管理
State
State
管理在
React
中是一种非常好的机制。我们可以使用
React
内置的
State
管理系统构
建大量的应用程序。不过,随着应用程序规模的不断扩张,
State
管理工作开始让我们
焦头烂额了。坚持让
State
存放在组件树的根节点的某个位置将会有助于减轻用户的工
作负担,不过即使如此,用户的应用程序膨胀到一定规模时,最明智的做法是将
State
数据和自身的层级隔离,独立于
UI
React
外部管理
State
的优点之一就是它将减少大量类组件的使用。如果没有使用
State
,那么很容易就可以确保用户的大部分组件是无状态的。当需要使用生命周期函
数时,用户只需要创建一个类即可,甚至可以将类的功能和
HOC
隔离,从而确保组件
只包含无状态的
UI
。无状态函数式组件更容易理解和测试。它们是纯函数,因此非常
适合构造严格意义上的函数式应用程序。
React
之外管理
State
意味着很多不同的事情。用户可以把
React
Backbone
模型搭
配使用,或者其他任意
MVC
库的模型
State
。用户可以创建专属于自己的
State
管理系
统。甚至可以使用全局变量、本地存储和
JavaScript
纯文本管理
State ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

React快速上手开发

React快速上手开发

Stoyan Stefanov
C++语言导学(原书第2版)

C++语言导学(原书第2版)

本贾尼 斯特劳斯特鲁普

Publisher Resources

ISBN: 9787519814236