How can we access updated states in the same function?
state = {
a: 1,
b: 2,
};
updateState = () => {
const { a, b } = this.state;
console.log("previous a", a);
console.log("previous b", b);
this.setState({ a: b, b: 3 });
console.log("New a", a); <-- getting previous value here
console.log("New b", b); <-- getting previous value here
};
is it possible to get a new value in the same function?
async and await are not working here. function method where we apply function as a 2nd parameter to the setstate is not working for the whole application.
please do not flag this question.