So i have a Simple App component at top level. This component calls store.getState() in it's render function and gets 'user' from store. If the user exists, it renders some containers using connect (from react-redux). Those containers are also accessing the same value ('user')in mapStateToProps. The problem is that in App component user exists, and it renders the containers, but in mapStateToProps that value is undefined. If I call getState in mapStateToProps (I know it's not the way to do things, you shouldn't do that) for debugging purposes, the value is there, user. But it's not if i access through the state passed down to mapStateToProps function.
Asked
Active
Viewed 615 times
2
-
2Could you include your code in the question? `store.getState()` in the render method is generally not a good idea since it will not cause the component to re-render when the store state changes. – Tholle Mar 15 '19 at 09:36
-
2I think this is what you're looking for : https://stackoverflow.com/questions/52074622/store-getstate-or-mapstatetoprops-in-component – S.Haviv Mar 15 '19 at 10:09