Reputation: 8841
I'm firing off an action when I get the user's current location to find markers within that location. I get the data, update my reducer.
However, when I console.log(this.props)
in my componentWillReceiveProps
, I still see the old state. If I navigate to another route, and then come back, I can see the updated props from the console log from componentWillReceiveProps
.
UPDATE: This was due to lack of understanding on my part of the component lifecycle. Look at the answer below :) .
Upvotes: 0
Views: 139
Reputation: 2391
That is the intended behavior! That function is called before the component rerenders, so that you can compare old state to 'current' state.
The reducer updates the state tree, which tells the connected component to rerender, and at that point this.props
should show you the old state of the component.
After the console.log, the component will continue to rerender unless directed otherwise, which is why when you navigate back you see the 'new props'.
The values that get passed through componentWillReceiveProps are the next props.
Your lifecycle code is essentially saying:
The doc's on the lifecycle are pretty excellent and can be found here
If that doesn't help out, where is the intended behavior of the component misfiring?
Upvotes: 2