reset: (values?: Record<string, any>, options?: Record<string, boolean>) => void
Reset either the entire form state or part of the form state.
Props
Reset
has the ability to retain formState. Here are the options you may use:
Name | Type | Description |
---|---|---|
values | object | An optional object to reset form values. |
keepErrors | boolean | All errors will remain. This will not guarantee with further user actions. |
keepDirty | boolean |
Important: this keep option doesn't reflect form input values but only dirty fields form state. |
keepValues | boolean | Form input values will be unchanged. |
keepDefaultValues | boolean | Keep the same defaultValues which are initialised via
|
keepIsSubmitted | boolean |
|
keepTouched | boolean |
|
keepIsValid | boolean |
|
keepSubmitCount | boolean |
|
Rules
For controlled components you will need to pass
defaultValues
touseForm
in order toreset
theController
components' value.When
defaultValues
is not supplied toreset
API, then HTML native reset API will be invoked to restore the form.Avoid calling
reset
beforeuseForm
'suseEffect
is invoked, this is becauseuseForm
's subscription needs to be ready beforereset
can send a signal to flush form state update.You can
reset
insideuseEffect
.
Examples
Video
The following video explains in detail each different formState
represents and functionality within the reset
API.
Thank you for your support
If you find React Hook Form to be useful in your project, please consider to star and support it.