score:22

Accepted answer

Setting the state is asynchronous so you would almost always see the old value. Instead, use the callback the function provides:

this.setState({
    loggedIn: val
}, () => console.log(this.state.loggedIn));

This is particularly useful when you need to do something AFTER setting a new state.


Related Query

More Query from same tag