Skip to content

mapStateToProps() not being called #1726

@richb-hanover

Description

@richb-hanover

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:

  • I understand that actions describe updates to a portion (a property) of that store.
  • I understand that each reducer is responsible for updating its slice/portion of the store. (And I definitely understand that the reducer must return a new object for its slice.)
  • I understand that mapStateToProps "plucks up" certain data from the store and passes it as props to the named component.

But... I haven't found a description of how actions, reducers, and mapStateToProps all relate to each other. My questions:

  • I think of the store as being an object, with properties that hold data about the application's state. Those top-level properties can be objects that provide a sub-tree for holding info about a portion of the application. Is this true?
  • When an action is dispatched to the store, what property (or sub-tree of the store) gets updated? It seems there's an automatic creation of/association to a property within the store, but how is that determined?
  • How does mapStateToProps "know" to listen for updates to the proper property/part of the store? What ties them together?
  • How could I debug this? What would I need to do to figure out why dispatching the action doesn't seem to fire mapStateToProps?
  • Or am I thinking about it all wrong... ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions