Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is the reducer called three times? #729

Closed
alesch opened this issue Sep 14, 2015 · 5 comments
Closed

Why is the reducer called three times? #729

alesch opened this issue Sep 14, 2015 · 5 comments
Labels

Comments

@alesch
Copy link

alesch commented Sep 14, 2015

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');
   // ....
@gaearon
Copy link
Contributor

gaearon commented Sep 14, 2015

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

@alesch
Copy link
Author

alesch commented Sep 14, 2015

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)
    }
  }
}

@gaearon
Copy link
Contributor

gaearon commented Sep 14, 2015

Please provide a runnable example to reproduce the issue, with expected and actual invocation count.
Otherwise it's hard to say.

@alesch
Copy link
Author

alesch commented Sep 14, 2015

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!

@gaearon
Copy link
Contributor

gaearon commented Sep 14, 2015

should my reducer be called once per action, and once on startup?

Reducer is called once on startup, and then once per every action.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants