1
votes

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?

1
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? - Ben Irving
Ye I put console.log and component is actually getting remounted, but I have no idea why this could be happening - Mister M
if it's being re-mounted it's probably something to with the parent. Can you add the parent component code too? - Will Jenkins
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? - Mister M
No you could post your comment as an answer and mark it as answered. - 10101010

1 Answers

1
votes

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.