Skip to content

reset

Reset form state and values

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:

NameTypeDescription
valuesobject

An optional object to reset form values.

keepErrorsboolean

All errors will remain. This will not guarantee with further user actions.

keepDirtyboolean

DirtyFields form state will remain, and isDirty will temporarily remain as the current state until further user's action.

Important: this keep option doesn't reflect form input values but only dirty fields form state.

keepValuesboolean

Form input values will be unchanged.

keepDefaultValuesboolean

Keep the same defaultValues which are initialised via useForm.

  • isDirty will be checked again provided valued against the original defaultValues.

  • dirtyFields will be updated again provided valued limited to the root level against the original defaultValues.

keepIsSubmittedboolean

isSubmitted state will be unchanged.

keepTouchedboolean

isTouched state will be unchanged.

keepIsValidboolean

isValid will temporarily persist as the current state until additional user actions.

keepSubmitCountboolean

submitCount state will be unchanged.

Rules

  • For controlled components you will need to pass defaultValues to useForm in order to reset the Controller components' value.

  • When defaultValues is not supplied to reset API, then HTML native reset API will be invoked to restore the form.

  • Avoid calling reset before useForm's useEffect is invoked, this is because useForm's subscription needs to be ready before reset can send a signal to flush form state update.

  • You can reset inside useEffect.

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.

Edit