【14】redux 之 redux-actions
2024-10-19 21:37:35
redux-actions
有两大法宝createAction
和handleActions
.
createAction
http://www.jianshu.com/p/6ba5cd795077
原来创建action
:
const startAction = () => ({ type: START });
使用redux-actions
创建action
:
import { createAction } from 'redux-actions';
const startAction = createAction(START);
handleActions
原来reducer
操作state
写法要使用switch
或if else
来匹配:
function timer(state = defaultState, action) {
switch (action.type) {
case START:
return { ...state, runStatus: true };
case STOP:
return { ...state, runStatus: false };
case RESET:
return { ...state, seconds: 0 };
case RUN_TIMER:
return { ...state, seconds: state.seconds + 1 };
default:
return state;
}
}
使用redux-actions``reducer
操作state
:
const timer = handleActions({
START: (state, action) => ({ ...state, runStatus: true }),
STOP: (state, action) => ({ ...state, runStatus: false }),
RESET: (state, action) => ({ ...state, seconds: 0 }),
RUN_TIMER: (state, action) => ({ ...state, seconds: state.seconds + 1 }),
}, defaultState);
http://blog.csdn.net/sinat_17775997/article/details/70176723
最新文章
- PHP 生成验证码
- Maven Eclipse (m2e) SCM connector for subclipse 1.10 (svn 1.8) 无法检测
- 学习笔记:Twitter核心数据类库团队的Hadoop优化经验
- Google Code Jam 2010 Round 1A Problem A. Rotate
- Request Session生命周期及struts1 中service的编写
- T—SQL用法剪辑,方便以后查看
- Stopwatch 类【转】
- 传统web和mvc的区别
- stl中的容器、迭代器和算法----vector中的find实现
- Day-17: 网络编程
- 【福大软工】 W班级总成绩排名2
- T-SQL动态查询(2)——关键字查询
- 213. House Robber II(动态规划)
- Oracle SQL 优化规则
- Spring-IOC实现【01-XML配置方式】
- [转载]AngularJS 指令 用法
- Nodejs学习笔记(十二)—定时任务(node-schedule)
- JavaScript浏览器对象模型(BOM)之window对象
- BZOJ3675 Apio2014 序列分割 【斜率优化】
- 蓝桥杯 历届试题 PREV-1 核桃的数量