I am trying to access this.state inside this.setState after a state is updated. I want user info to be set to state then from that source of truth wanted to save that user data into local storage
setUserInfo = userInfo => {
this.setState(
{ username: userInfo.userName, password: userInfo.userPass },
prevState => {
//trying to access this.state but unable to
console.log(prevState);
// or
console.log(this.state.username);
}
);
};
I know that this could code could do it but will the second setstate be confirm to run after the first setState?
setUserInfo = userInfo => {
this.setState({ username: userInfo.userName, password: userInfo.userPass });
this.setState(prevState => {
prevState;
});
};
prevStateis updated state inside a callback. will the second setstate be confirm to run after the first setState? - it will, but you don't need second setState. - Estus Flask