bmuk
bmuk

Reputation: 121

redux-actions handleActions isn't changing the state

So I have a bunch of ducks style redux modules that look like this:

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)

then, in reducers.js I do this:

import error from './error'

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

yet, when I dispatch(setError("ERROR")) I see the action in redux devtools, but the state does not change

Upvotes: 0

Views: 644

Answers (1)

fkulikov
fkulikov

Reputation: 3199

You are passing map with wrong keys to handleActions. You don't want keys to be SET and CLEAR, but their values instead (error/SET and error/CLEAR). To do so you have to wrap them in square brackets:

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

Upvotes: 1

Related Questions