I am working on my first React / Redux project. Everything went well, and then I tried to create a new gearbox. I thought it was pretty simple, but when I load the page, I get the error message "Reducer X returned undefined during initialization". The trace says this happens in combReducers (). I found a couple of similar questions, but they did not solve the problem.
On this question: Why do I get "The reducer [...] is returned undefined during initialization", despite providing initialState for createStore ()?
The problem was that they used initialState in createStore (), which I am not doing.
On this question: Why does my Redux reducer consider my state to be undefined?
The problem was the lack of a default return value in the reducer that I have.
My abbreviation code is below. I have console.log () at the beginning and it is not called at all.
reducers / reducer_which_sorter.js
import { SORT_CAMPERS } from '../actions/index'; export default function(state = null, action) { console.log("action is", action); switch(action.which) { case 'recent': case 'alltime': return action.which; break; default: return state; } return state; }
gearboxes / index.js
import { combineReducers } from 'redux'; import Campers from './reducer_camper_list'; import ActiveSorter from './reducer_which_sorter'; const rootReducer = combineReducers({ campers: Campers, activeSorter: ActiveSorter }); export default rootReducer;
Everything compiles fine. No errors from webpack. I have double, triple and quadruple file path checks. I do not see any typos. Can someone see something that I don't see here?
source share