Redux: Why is the reducer called three times?

Created on 14 Sep 2015  路  5Comments  路  Source: reduxjs/redux

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');
   // ....
question

Most helpful comment

combineReducers() probes your reducers to check for common mistakes before actually using them.
Don鈥檛 worry about it!

All 5 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jbri7357 picture jbri7357  路  3Comments

rui-ktei picture rui-ktei  路  3Comments

vslinko picture vslinko  路  3Comments

dmitry-zaets picture dmitry-zaets  路  3Comments

benoneal picture benoneal  路  3Comments