In the counter example, the reducer is called three times upon start.
The same happens in todomvc example.
Why is this?
Thanks!
I added:
export default function counter(state = 0, action) {
console.count('reducer');
// ....
combineReducers() probes your reducers to check for common mistakes before actually using them.
Don鈥檛 worry about it!
The reason I started looking into this is that in another project of mine, the reducer is called two times for every action. I am not using combineReducers there.
function defaultReducer (state, action) {
return state;
}
function reducer (state, action) {
return {
data : defaultReducer(state.data, action),
ui: {
mainMenu: mainMenuReducer(state.ui.mainMenu, action)
}
}
}
Please provide a runnable example to reproduce the issue, with expected and actual invocation count.
Otherwise it's hard to say.
I guess the question is: without using combineReducers, should my reducer be called once per action, and once on startup?
Or are there other invocations behind the scenes?
PS: Thanks a lot for Redux and for your time answering this questions. You rock!
should my reducer be called once per action, and once on startup?
Reducer is called once on startup, and then once per every action.
Most helpful comment
combineReducers()probes your reducers to check for common mistakes before actually using them.Don鈥檛 worry about it!