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
mapStateToProps() not being called #1726
Comments
Have you gone through http://redux.js.org/docs/Troubleshooting.html and verified your case is not one of the issues it describes?
Yea. Store holds the top-level state object internally. It provides access to that object from
No, there is no automatic creation of anything. The store just starts pointing to the result of calling your root reducer. If your root reducer is a function you wrote yourself, its result is what you’ll get after dispatching an action: function counter(state = 0, action) {
if (action.type === 'INCREMENT') {
return state + 1; // will become the next value of store.getState() after store.dispatch()
}
return state;
} If you generate the root reducer with something like function root(state = {}, action) {
return {
foo: foo(state.foo, action),
bar: bar(state.bar, action)
}
} This is where the properties on the state often come from. Their values are determined by what your
You pass
Add a middleware like https://github.com/theaqua/redux-logger. Verify that the state updates after the action in the way you expect. If
Both of these cases are described in http://redux.js.org/docs/Troubleshooting.html. In the future, we ask that you try to ask questions on StackOverflow first, and use the issue tracker when you’re confident there is a bug in the library that you’re able to consistently reproduce with an example you can share. Thanks! |
Answering in order:
Hopefully that helps clear things up. Beyond that, as Dan said: usage questions are generally better suited for Stack Overflow. Also, the Reactiflux community on Discord has a bunch of chat channels dedicated to React-related technologies, including Redux, and there's always a number of people hanging around willing to answer questions. There's an invite link at https://www.reactiflux.com . |
@richb-hanover You've probably witnessed the shallow compare which is performed by the react-redux connect. This means that objects nested within other objects won't result in rerender even if they are modified because only the root key are checked for modifications. |
@richb-hanover In my case, @gaearon detected the issue:
I was using this fix and this was the resulting code
Since I didn't pass the |
I've read tons of documentation - on all the popular sites - but nowhere have I found an answer. I'm asking here to see if I have missed some documentation, or a vital piece of understanding.
The problem I see is that my component's mapStateToProps() function is only called once (at initialization). It never is called again, even when the reducer gets called. I am beginning to think that it's because I don't understand how actions/reducers/props are all tied together.
Let me first say what I do know:
But... I haven't found a description of how actions, reducers, and mapStateToProps all relate to each other. My questions:
The text was updated successfully, but these errors were encountered: