You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I made a custom hook useAutoSave which is used on my form component.
bank-create-update-form.tsx - This form handles both create mutation & update mutation. Everytime successful create/update mutation I reset the form via form.reset(dataFromMutationResponse)
constBankCreateUpdateForm=({ className, ...formProps}: IBankFormProps)=>{constform=useForm<TBankFormValues>({resolver: standardSchemaResolver(BankSchema),reValidateMode: 'onChange',mode: 'onSubmit',defaultValues: {name: formProps.defaultValues?.name||'',description: formProps.defaultValues?.description||'',media: formProps.defaultValues?.media,media_id: formProps.defaultValues?.media_id,},})// ...other stuff/ api mutationsuseAutoSave({
form,onSave: ()=>console.log('auto save called by autoSave()'),// api mutation calldelay: 2000,})return(// ...UI)}
I always rely on the form state since I provide defaultValues via props (initial data), and I call form.reset() after a successful response.
The issue I’m facing is that when I type a single character into an input:
Typing 'A' → does not trigger autoSave
Typing 'B' (making it "AB") → autoSave is triggered
So the first input change isn’t being detected properly.
simplescreenrecorder-2025-09-24_13.57.26.mp4
As a temporary workaround, I created a headless component that uses useWatch. Placing it as a separate component prevents unnecessary re-renders of the entire form, and it works correctly.
However, I’d like to know if there’s a way to make form.watch handle this properly without needing to rely on external packages to check isDirty/dirtyFields.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I made a custom hook
useAutoSave
which is used on my form component.bank-create-update-form.tsx
- This form handles both create mutation & update mutation. Everytime successful create/update mutation I reset the form via form.reset(dataFromMutationResponse)use-auto-save.ts
I always rely on the form state since I provide defaultValues via props (initial data), and I call form.reset() after a successful response.
The issue I’m facing is that when I type a single character into an input:
Typing 'A' → does not trigger autoSave
Typing 'B' (making it "AB") → autoSave is triggered
So the first input change isn’t being detected properly.
simplescreenrecorder-2025-09-24_13.57.26.mp4
As a temporary workaround, I created a headless component that uses useWatch. Placing it as a separate component prevents unnecessary re-renders of the entire form, and it works correctly.
However, I’d like to know if there’s a way to make form.watch handle this properly without needing to rely on external packages to check isDirty/dirtyFields.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions