reactjsreact-hook-form

react-hook-form - how to reset formState.isDirty after form submitting


as I wrote in the title, please give me a hint on how to reset isDirty field from formState object.

In my application, I have a 'save' button which is disabled by default. When I change the value of any input the button is set to enabled because isDirty state is changed to true. After a successful save action, I want to make my save button disabled again (so I need to set isDirty as false again).


Solution

  • After successful form submission, you can reset form to its original state using reset from useForm hook. This will reset formState and isDirty value will be false.

    Docs: https://react-hook-form.com/docs/useform/reset