redux在react-native上使用(五)--redux-actions使用
发布时间:2020-12-15 07:29:08 所属栏目:百科 来源:网络整理
导读:redux-actions 有两大法宝 createAction 和 handleActions . createAction 原来创建 action : const startAction = () = ({ type: START }); 使用 redux-actions 创建 action : import { createAction } from 'redux-actions';const startAction = createAct
createAction原来创建 const startAction = () => ({ type: START }); 使用 import { createAction } from 'redux-actions'; const startAction = createAction(START); handleActions原来 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; } } 使用 const timer = handleActions({ START: (state,action) => ({ ...state,runStatus: true }),STOP: (state,runStatus: false }),RESET: (state,seconds: 0 }),RUN_TIMER: (state,seconds: state.seconds + 1 }),},defaultState); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |