reset() does not clear inputs wrapped with useController unless defaultValues are set #12883
-
sandbox: https://codesandbox.io/p/devbox/v23s9qDescribe the bugWhen using Steps to reproduce
Expected behaviorCalling Workarounds
Additional contextIt would be helpful if react-hook-form’s
This would improve usability for large and dynamic forms using controlled components wrapped by |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I don't think there's an easy way to handle all of the potential use-cases. For example, if the form contains these values, what should it be reset to? {
people: [
{
first: "John",
last: "Smith",
}
]
} There are several alternatives that this could be {
people: undefined,
} {
people: []
} {
people: [
{
first: undefined,
last: undefined,
}
]
} {
people: [
{
first: "",
last: "",
}
]
} Setting all of the fields to Improperly resetting the form could cause type issues or validation issues. If you want a custom You could do something like the following:
You would need to write your own |
Beta Was this translation helpful? Give feedback.
-
You may also want to look at something like https://github.com/toiroakr/zod-empty if you don't want to hard-code the default values. |
Beta Was this translation helpful? Give feedback.
I don't think there's an easy way to handle all of the potential use-cases. For example, if the form contains these values, what should it be reset to?
There are several alternatives that this could be
reset()
to.Setting all of the fields to
undefined
is problematic if a form is controlled and React will complain that controlled components are being changed …