1

I have a situation where the props in a container with mapStateToProps are updating, the props in the component are updating (just a string), the component is re-rendering.... and componentDidUpdate is just not going off.

So here is my connect method:

export default connect( state => { console.log("token",state.Auth.idToken); return { token: state.Auth.idToken, isLoggedIn: state.Auth.idToken !== null ? true : false } }, {login} )(SignIn); 

As you can see here, I take token with mapStateToProps, I then for debug purposes display this token in render function.

<div className="isoLoginContent"> {this.props.token} </div> 

So this token is empty at first, then when I update it using redux-saga and reducer, token correctly displays in render function, so component is re-rendering. But componentDidUpdate is not firing. I have no custom shouldComponentUpdate and I'm not using PureComponent. What else could be causing this?

5
  • I have seen problems in the past, whereby the component is actually being remounted rather than updated. Can you fire off a console.log in CDM and see if that is happening here? Commented Jul 31, 2019 at 8:12
  • Ye I put console.log and component is actually getting remounted, but I have no idea why this could be happening Commented Jul 31, 2019 at 8:19
  • if it's being re-mounted it's probably something to with the parent. Can you add the parent component code too? Commented Jul 31, 2019 at 8:20
  • I got it, I debugged and found history.push which was trying to push to a new url but it was redirecting back to login page because token was not set yet. I adjusted logic accordingly and now its working. Thanks a lot. I guess I should delete this question? Commented Jul 31, 2019 at 8:25
  • 1
    No you could post your comment as an answer and mark it as answered. Commented Jul 31, 2019 at 8:28

1 Answer 1

2

Thanks to @benirving92's suggestion that component was actually remounting instead of updating, I debugged and found history.push which was trying to push to a new url but it was redirecting back to login page because token was not set yet. I adjusted logic accordingly and now its working. Thanks for help.

Sign up to request clarification or add additional context in comments.

1 Comment

I can't for 2 days

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.