Reputation: 762
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);
}
}
Upvotes: 1
Views: 234
Reputation: 2599
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.
Upvotes: 1
Reputation: 52133
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.
Upvotes: 2