Problem
A submit button is disabled only after state updates to 'loading'. Under rapid user interaction, multiple clicks can occur before the UI visually reflects the disabled state.
- ●User clicks button rapidly.
- ●State update is scheduled but not yet committed.
- ●Multiple submit handlers execute.
- ●Duplicate API calls are triggered.
Because state updates are asynchronous, multiple click events can be processed before the button becomes disabled in the DOM.
Solution
Use a synchronous guard that does not rely on React render timing. A mutable ref blocks duplicate execution immediately before state updates propagate.
The ref acts as an immediate execution lock. It prevents duplicate side effects before React re-renders and disables the button.
UI state updates are not synchronous execution guards. When side effects must not run more than once, protection must exist outside the render cycle. Immediate execution locks prevent duplicate network calls and inconsistent server state.
Keywords
double submit bug, frontend edge case, react button disable race, ui correctness, state safety