所以我有一堆鸭子样式的redux模块看起来像这样:
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"))时,我看到redux devtools中的动作,但状态没有改变
答案 0 :(得分:1)
您正在将包含错误密钥的地图传递给handleActions
。您不希望密钥为SET
和CLEAR
,而是取其值(error/SET
和error/CLEAR
)。为此,你必须将它们包在方括号中:
export default handleActions({
[SET]: (error, action) => action.payload,
[CLEAR]: (error, action) => ""
}, "")