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

timdorr picture timdorr  路  56Comments

acdlite picture acdlite  路  54Comments

markerikson picture markerikson  路  51Comments

erikras picture erikras  路  63Comments

gaearon picture gaearon  路  61Comments