Does this look like a reasonable, if verbose, way to make sure that each click does not stack requests to saveOperation?
I'm using RxJS and storing the instance of the subscription in a mutable ref so it persists between renders. Then, if one exists, I cancel it before starting a new one.
const saveSubscription = useRef<Subscription>(); // RxJS Subscription (cancellable fetch)
const handleChange = () => {
saveSubscription.current?.unsubscribe();
saveSubscription.current = saveOperation({ ...data }).subscribe();
}
...
<input type="text" onClick={() => handleChange()} ref={fileInput} />
switchMapin order to make use that the current observable which handles the request will be unsubscribed if the click stream emits.