状态管理之redux概念综述(未完待更)

Redux

store

存储state,唯一store。
创建store
createStore([reducer], [preloadedState], applyMiddleware([middlewares]))

Provider

reducer

唯一可直接修改state的方式,为function,传入state,action,返回state一个新的对象

combineReducers

组合多个reducer

官方示例

rootReducer = combineReducers({potato: potatoReducer, tomato: >tomatoReducer})
// This would produce the following state object
{
 potato: {
   // ... potatoes, and other state managed by the potatoReducer ...
 },
 tomato: {
   // ... tomatoes, and other state managed by the tomatoReducer, maybe >some nice sauce? ...
 }
}

action

带有key为type的一个object,引入redux-thunk时可为function以处理异步逻辑。
通过dispatch([action])的方式,发起一个动作 => 中间件处理逻辑之后 => 调起reducer执行对应type的代码,返回新的state。

dispatch

发起一个动作,传入action,该方法由store提供。
store.dispatch

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,136评论 0 10
  • 学习必备要点: 首先弄明白,Redux在使用React开发应用时,起到什么作用——状态集中管理 弄清楚Redux是...
    贺贺v5阅读 12,887评论 10 58
  • 使用redux+react已有一段时间,刚开始使用并未深入了解其源码,最近静下心细读源码,感触颇深~ 本文主要包含...
    字节跳动技术团队阅读 5,484评论 0 5
  • 本文将开始详细分析如何搭建一个React应用架构。 一. 前言 现在已经有很多脚手架工具,如create-reac...
    字节跳动技术团队阅读 9,822评论 1 23
  • 有时从一地点切换到另一地点,急急的,好像脚下踩了风火轮,再加上经常穿了一身运动黑,瞬间会有如此感觉——再佩一把剑,...
    白藜芦醇阅读 1,248评论 0 0