I create a toy example with NodeJS and redux. I create a store like this:
var initialState = {config: defaultConfig, customData: data};
const store = createStore(reducers, initialState)
I make sure defaultConfig
and data
are defined, i.e. i really stop the debugger before the statement and I can confirm the config is really there. However, inside the reducers, the state is undefined
. Why?!
The reducers are:
const configReducer = (config: any, action: any): any =>{
return config;
}
const customData = (customData: any, action: any): any => {
return customData;
}
const reducers = combineReducers({config: configReducer, customData: customDataReducer})
So I am explicitly giving an initial state, but redux will call the reducers with undefined
.
I know I could put the initial state as default parameter in the reducers, or use any other work around. That is not the question here.
The question is: why this is not working if I pass the initial state when building the store.