01 · Before and afterThe pattern
const gen = useRef(0);
const invalidate = () => { gen.current++; setBusy(false); };
async function onFile(file: File) {
const mine = ++gen.current; setBusy(true);
const value = await process(file); // slow
if (mine !== gen.current) return; // something newer happened
form.setValue("logo", value); setBusy(false);
}
// call invalidate() from: manual edit, clear, dialog close, form reset02 · Run it on your appThe check
If a user changes their mind while an upload is still processing, can the old upload ever overwrite the new choice?
If the honest answer is no or not sure, this is worth a look before it reaches production.