question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

State not changed in component props but has changed in the store.

See original GitHub issue

I 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:

redux state

app state

Has anyone else seen this before? Any ideas where I can look for the issue?

The code is very simple at this point, just connecting 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:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
timdorrcommented, Aug 3, 2017

You have to wrap your component in withRouter when you use connect.

0reactions
Panoploscommented, Aug 4, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found