reset() does not clear inputs wrapped with useController unless defaultValues are set #12861
Unanswered
Best-Sardar
asked this question in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
sandbox: https://codesandbox.io/p/devbox/v23s9q
Describe the bug
When using
useController
to wrap input fields in react-hook-form, callingreset()
without arguments does not clear the input fields unlessdefaultValues
are explicitly set for those fields inuseForm
. This behavior can be unintuitive and inconvenient for large forms where setting default values for every field is impractical.Steps to reproduce
useController
.defaultValues
inuseForm
.reset()
without any arguments.Expected behavior
Calling
reset()
without arguments should clear all input fields (i.e., reset their values to empty or undefined), regardless of whetherdefaultValues
were provided.Workarounds
defaultValues
for each field works but can be cumbersome.reset({ fieldName: '' })
with empty values per field is tedious for large forms.undefined
values inside custom inputs by defaulting to empty string is possible but adds boilerplate.Additional context
It would be helpful if react-hook-form’s
reset()
either:defaultValues
were provided,This would improve usability for large and dynamic forms using controlled components wrapped by
useController
.Beta Was this translation helpful? Give feedback.
All reactions