一、添加依赖
1. yarn add redux react-redux redux-thunk react-router-dom
// redux-thunk 让action可以返回函数的中间件
2. yarn add redux-logger --dev
//辅助redux,可在打印中看到redux一切行为和数据
二、创建项目目录结构
目录结构图
三、配置Redux(<font color=#ff0000>文件具体路径请看项目目录结构</font>)
1. actionTypes 公用属性
actionTypes公用type属性
2. 添加一个action
action行为
3. 写入与action对应的reducer
处理action传来的信息
4. 合并reducer ,便于处理reducer过多导致的麻烦
合并Reducer
5. 配置store
配置store
-
将store写入启动程序中
添加store进根目录index.js中 -
结束
三、配置路由
配置路由,并且尝试使用redux