I know that react will not update the state
immediately when you call setState
.
In this example how can i access the updated state ?
changeInputHandler(e) {
let value;
let name = e.target.name;
if(e.target.type === "checkbox") {
value = e.target.checked;
} else {
value = e.target.value;
}
this.setState({
[name]: value
});
//How can i use updated state here?
}
and i know that one solution is to use setTimeout
, but is there any alternative?