Redux

React

1. 基本
1.1 为什么学习Redux?

1. 基本

工作流程:

sequenceDiagram 动作 creators ->> store: 首先,用户发出 Action {dispatch (action)} 动作 creators -->> reducers: store ->> reducers: Store 自动调用 Reducer,并且传入两个参数:当前 State 和收到的 Action。{previousState,action} reducers ->> store: Reducer 会返回新的 State.{newState} store ->> react components: State 一旦有变化,Store 就会调用监听函数 ✅{state} 动作 creators -> react components: 触发重新渲染 View

工作流程图2:

graph TB A[动作 creators] -- 用户发出 Action --> B((store)) B -- previousState,action --> C(reducers) C -- newState --> B B -- State --> D{react components} D -- 触发重新渲染 View --- A

1.1. 为什么学习Redux?

我们的代码必须管理比以往更多的状态。
因为您无法控制其状态的时间,原因和方式。

上一篇:combineReducers() 用法详解


下一篇:Redux中间件