handleChange(event){
this.setState({value: event.target.value});
console.log("You picked up" + this.state.value);
}
<select value={this.state.value} onChange={this.handleChange} onClick={this.handleOnClick}>
I just wonder why the handleChange() always returns me the previous selected vlaue rather than the currently selected?
Here is my full code: https://codepen.io/franva/pen/owbmaQ
setState()
is asynchronous. Try
this.setState({ value: event.target.value }, () => {
console.log("You picked up" + this.state.value);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.