1

Orignal Error Msg:

Store does not have a valid reducer. Make sure the argument passed to combineReducers is an object whose values are reducers.

Here is the: reducer.js

import { combineReducers } from 'redux';
import list_reducer from './reducers/list_reducer.js';


export default combineReducers({
  list_reducer
});

Here is the: list_reducer.js

const list_reducer = (state = {
  operation: 'success',
  userlist: []
}, action) => {

  switch (action.type) {
    case "FETCH_USER_FULFILLED":
      return {
        ...state,
        userlist: state.userlist.concat(...action.payload)
      }


    case "UPDATE_USER_DETAILS_FULFILLED":
      return {
        ...state,
        userlist: state.userlist.concat(...action.payload)
      }


    case "DELETE_USER_FULFILLED":
      return {
        ...state,
        userlist: state.userlist.concat(...action.payload)
      }


    case "REGISTER_USER_FULFILLED":
      return {
        ...state,
        userlist: state.userlist.concat(...action.payload)
      }


  }

};

export default list_reducer;

Tried Everything from here

Have been stuck on this error for quite a while now and I am on clock so any help will be appreciated.

UPDATE: HERE IS WHAT CONSOLE.LOG(list_reducer) looks like from reducer.js

list_reducer

list_reducer

 function list_reducer() {
    var _state$userlist, _state$userlist2, _state$userlist3, _state$userlist4;

    var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { operation: 'success', userlist: [] };
    var action = arguments[1];


    switch (action.type) {
        case "FETCH_USER_FULFILLED":
            return Object.assign({}, state, {
                userlist: (_state$userlist = state.userlist).concat.apply(_state$userlist, _toConsumableArray(action.payload))
            });

        case "UPDATE_USER_DETAILS_FULFILLED":
            return Object.assign({}, state, {
                userlist: (_state$userlist2 = state.userlist).concat.apply(_state$userlist2, _toConsumableArray(action.payload))
            });

        case "DELETE_USER_FULFILLED":
            return Object.assign({}, state, {
                userlist: (_state$userlist3 = state.userlist).concat.apply(_state$userlist3, _toConsumableArray(action.payload))
            });

        case "REGISTER_USER_FULFILLED":
            return Object.assign({}, state, {
                userlist: (_state$userlist4 = state.userlist).concat.apply(_state$userlist4, _toConsumableArray(action.payload))
            });

        default:
            return Object.assign({}, state);
    }
}
HVenom
  • 712
  • 1
  • 10
  • 25

2 Answers2

2

You always needs to return state in your default case:

default:
  return state;

Otherwise unknown actions will cause the state to become undefined. Redux checks for this case and throws an error. Remember that all the top-level reducers are going to run for every action type, not just the ones it has cases for. Read more in the docs.

Aaron Beall
  • 49,769
  • 26
  • 85
  • 103
  • Yeah, you probably haven't reached this yet, it sounds like your reducer isn't importing at all. What bundler are you using? What do you get if you `console.log(list_reducer)` – Aaron Beall Apr 20 '18 at 14:38
1

Actually, it seems that you're using combineReducers several times, which can produce such error. Review carefully your imports of reducer.js file and check whether it passed into another combineReducer function.

Denys Kotsur
  • 2,579
  • 2
  • 14
  • 26
  • Yup there was another combineReducer inside store.js file thanks mate you solved my hours of frustation. – HVenom Apr 20 '18 at 22:57