Skip to Content
Node与Express开发(第2版)
book

Node与Express开发(第2版)

by Ethan Brown
June 2021
Intermediate to advanced
290 pages
9h 21m
Chinese
Posts & Telecom Press
Content preview from Node与Express开发(第2版)
184
|
第
16
章
16.4.6
 状态管理
规划和设计一个
React
应用的大部分架构性工作是围绕着状态管理进行的——通常不是单
个组件的状态管理,而是在多个组件之间如何共享和协同状态。我们的示例应用确实共享
了一些状态:
Vacations
组件把一个度假产品对象传入
Vacation
组件,而
Vacation
组件把
度假产品的
SKU
传入
NotifyWhenInSeason
订阅组件。但目前为止,我们的信息只能在组
件树上
往下
走,如果需要信息
往上
走该怎么办?
最常见的做法是在组件之间传递负责更新状态的函数。例如,
Vacations
组件会有一个修
改度假产品的函数,可以把它传入
Vacation
组件,而在
Vacation
里面,也可以把这个函
数传入
NotifyWhenInSeason
组件。当
NotifyWhenInSeason
调用它来修改度假产品时,组件
树顶层的
Vacations
就会发现有东西被修改了,于是
Vacations
组件会得到重新渲染,进
而所有下层组件都得到了重新渲染。
这听起来既累人又复杂,有时候确实如此,不过一些技术可以提供帮助。它们多种多样,
有时候也比较复杂,这里不能完整地覆盖这部分内容(何况本书也不是关于
React
的)
,不
过我可以给你指出进一步阅读的方向。
Redux
在考虑
React
应用中全面的状态管理方案时
,
Redux
通常是人们第一个会想到的。它是
最先出现的正式状态管理架构之一,现在仍广受欢迎。它的概念极其简单,到现在仍
是我最偏爱的状态管理框架。即便最终没有选择
Redux
,我还是推荐你看看它的创建者 ...
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

面向对象的思考过程(原书第5版)

面向对象的思考过程(原书第5版)

马特 魏斯费尔德
精通模块化JavaScript

精通模块化JavaScript

Nicolás Bevacqua

Publisher Resources

ISBN: 9787115565099