简体   繁体   中英

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).

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/api/useform/reset

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM