After reading about Controlled Components and setState I'm having problems with building a coherent mental model of React.
The example of a Controlled Component from the mentioned doc, contains following fragments relevant to my question:
handleChange(event) {
this.setState({value: event.target.value});
}
render() {
return (
<input type="text" value={this.state.value} onChange={this.handleChange}/>
)
}
The question is: since the user can perform arbitrary edit actions at high speed, and setState
is presumably asynchronous, is it possible, that at moment t0, onChange
was called with event.target.value='a'
, which caused setState({ value: 'a'})
, then at moment t1 user changes text to 'b', and at moment t2, the "queued" request made via setState kicks in, and the text gets replaced with a stale value 'a'?