2017-02-11 73 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) => "" 
}, "")