1
  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

Franva
  • 6,565
  • 23
  • 79
  • 144
  • Possible duplicate of: https://stackoverflow.com/questions/29490581/react-state-not-updated. This behavior is described in detail here: https://facebook.github.io/react/docs/react-component.html#setstate – Freeman Lambda Jun 10 '17 at 11:42
  • Possible duplicate of [Change state on click react js](https://stackoverflow.com/questions/41278385/change-state-on-click-react-js) – Shubham Khatri Jun 10 '17 at 12:54

1 Answers1

3

setState() is asynchronous. Try

this.setState({ value: event.target.value }, () => {
  console.log("You picked up" + this.state.value);
});
Amberlamps
  • 39,180
  • 5
  • 43
  • 53