In the follow example, we have a button that starts and upload, and disables itself while the upload is in progress. It reenables itself when the upload is done.
Is it possible that, due to the asynchronous nature of React's setState, for a user that is clicking really fast, to trigger the onClick callback twice before the button is disabled?
Please do not answer with solutions for how to avoid this scenario, I want to know if this scenario if even possible in the first place and if so, how to reproduce it.
import React from 'react';
import ReactDOM from 'react-dom';
class App extends React.Component {
constructor (props) {
super(props)
this.state = {
uploadDisabled: false
}
}
upload = () => {
this.setState({
uploadDisabled: true
})
fetch('/upload').then(() => {
this.setState({
uploadDisabled: false
})
})
}
render () {
return (
<div>
<button disabled={this.state.uploadDisabled} onClick={this.upload}>
Upload
</button>
</div>
)
}
}