Time: 20200129
前置要求
- React基础
Redux
Redux is a predictable state container for JavaScript apps.
从中可以摘出三个关键词:
- It is for JavaScript apps
- It is a state container
- It is predictable
For JavaScript apps
Redux并不仅仅限于用在React中,还可以用在其他的框架,比如Vue, Angular等。
State container
Redux存储应用的状态。

应用的状态由所有的组件的来代表。
Predictable
为什么说可预测呢?

借助于Redux,应用状态的变化可以预测。
React + Redux?
- 为什么要在React应用中使用Redux?
- React的组件不是有自己的状态了吗?
- 为什么需要用其他的工具来管理状态?
使用React的状态管理

受限于React的单向数据流,外部传入的数据需要以props的形式传给子组件,非常不灵活。
使用Redux的状态管理

不用Redux真的有问题吗?
比如我们有:
- React Context,可以避免props的层层传递
- useContext + useReducer?
Redux 1.0发布时间是2015年8月
React-Redux
- React: UI库
- Redux: 状态管理库
二者是独立工作的,为了在项目中使用,我们可以采用react-redux
库。

总结

END.
网友评论