State not changed in component props but has changed in the store.
See original GitHub issueI have run into an issue where I am updating the redux store via a reducer, but the app’s copy of the state is not updated. See these shots below:
Has anyone else seen this before? Any ideas where I can look for the issue?
The code is very simple at this point, just connect
ing props as follows:
export default (hash) => {
const mapStateToProps = (state: Object) => ({
navigatable: state.modal.navigatable
})
const mapDispatchToProps = (dispatch: Dispatch) => ({
toggleNavigability() {
dispatch(toggleNavigability())
}
})
return [
connect(mapStateToProps, mapDispatchToProps),
lifecycle({
componentDidMount() {
$(hash)
.modal({
detachable: false,
onHidden: () => {
if (this.props.navigatable) {
this.props.history.goBack()
}
this.props.toggleNavigability()
return true
}
})
.modal('show')
},
componentWillUnmount() {
if (this.props.navigatable) {
this.props.toggleNavigability()
$(hash).modal('hide')
} else {
this.props.toggleNavigability()
}
}
})
]
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
React state is not changing after the props change
Please take note that I am using isEqual from lodash/isEqual to deep check equality between state and props otherwise it will update ...
Read more >Why React doesn't update state immediately - LogRocket Blog
When developing React applications, you may have noticed that state updates don't immediately reflect new values after being changed.
Read more >Lifting State Up - React
Often, several components need to reflect the same changing data. We recommend lifting the shared state up to their closest common ancestor.
Read more >Why isn't my React component updating (using Redux)?
But the most common reason is that you mutate the state in your reducers. ... see that the state has changed, it will...
Read more >Connect: Extracting Data with mapStateToProps - React Redux
It is called every time the store state changes. It receives the entire store state, and should return an object of data this...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You have to wrap your component in
withRouter
when you useconnect
.That was the answer to what I was looking for but didn’t actually solve the problem. LOL My assumption that redux state would be reflected in the component props after
componentWillUnmount()
was wrong… Thanks for the help, anyway.