Hm, title basically sums it up.
I have a Navbar component and a NavbarContainer:
NavbarContainer
export default NavbarContainer = createContainer(() => {
const signedIn = Meteor.user() !== null;
console.log("signedIn: " + signedIn);
console.log("createContainer() got called!");
return {
signedIn
}
}, Navbar);
componentWillReceiveProps method
componentWillReceiveProps() {
console.log("componentWillReceiveProps()");
console.log("componentWillReceiveProps() update: " + this.props.signedIn);
if (this.state.loggedIn != this.props.signedIn) {
console.log("State changed, updating!");
this.setState({
loggedIn: this.props.signedIn
});
} else {
console.log("State didn't change, no need to update!");
}
}
In Navbar I have the classical āLogin, Registerā, and once user is logged in, it shows āHi thereā. Also once logged in, the dropdown menu changes and this time includes the Logout btn that is linked with this code:
Logout method
logout(event) {
Meteor.logout();
console.log("Logging out");
}
In all the other cases, this works. Ie, not signed in -> login -> it shows āHi thereā. I can close the site and open it again, itāll still show āHi thereā etc, but the weird thing is once Iām logged in and I click logout, this is what happens in my output (for debugging purposes).
Console output
signedIn: false (this is the console.log() statement from the container above)
Navbar.jsx:234 createContainer() got called!
Navbar.jsx:60 componentWillReceiveProps() (this is a console.log() I simply put in componentWillReceiveProps())
Navbar.jsx:61 componentWillReceiveProps() update: true (this is the weird part! should be FALSE because the first line in output is āfalseā)
Conclusion?!
So what Iām seeing is:
Upon logging out, in the createContainer, the code is noticing that Meteor.user() is null (user signed out), but while itās sending that info as props to Navbar component it suddenly changes into opposite value (user is still here)?
Iām really banging my head against the wall, because this thing -> value suddenly changing between the container and it getting received in the component - is something I havenāt run into yet.
EDIT: Once I manually refresh the page afterwards (after clicking logout), it correctly shows that Iām not logged in. If it helps.