2017-02-11 76 views
0

所以我有一大堆的鸭式的终极版的模块,像这样:终极版,行动handleActions是不会改变的状态

import { createAction, handleActions } from 'redux-actions' 

const SET = "error/SET" 
const CLEAR = "error/CLEAR" 

export default handleActions({ 
    SET: (error, action) => action.payload, 
    CLEAR: (error, action) => "" 
}, "") 

export const setError = createAction(SET) 
export const clearError = createAction(CLEAR) 

然后,在reducers.js我这样做:

import error from './error' 

export default combineReducers({ 
    error, 
    ... 
}) 

,当我派遣(SETERROR(“ERROR”))我看到终极版devtools的动作,但状态不改变

回答

1

你传入地图错键handleAtions。您不希望密钥为SETCLEAR,但它们的值代替(error/SETerror/CLEAR)。要做到这一点,你必须把它们放在方括号中:

export default handleActions({ 
    [SET]: (error, action) => action.payload, 
    [CLEAR]: (error, action) => "" 
}, "")