Open Menduist opened 1 day ago
I think this is the correct behavior. If reset
always looked at looked at the latest defaultValues
, there would no longer be a guarantee that it would actually reset to the expected values. And if resetAfterSubmit
had different behavior than onSubmitSuccess={() => form.resetForm()}
that would break expectations as well.
But I think this is worth clarifying in the docs.
We could potentially add first-calls support for this case by letting you specify something like resetAfterFormSubmit="reinitialize"
or by adding a key
to useForm
that would reset & reinitialize.
I've added a Worky2
to the example that uses a remix Form
, you'll see that it behaves as I would expect (updates the values)
IMO, the defaultValue
of each field should always be up to date with the defaultValues
of useForm
, and thus the reset should always put back the latest defaultValues
. This stays consistent with "vanilla react"
Which packages are impacted?
@rvf/react
@rvf/remix
@rvf/zod
@rvf/yup
zod-form-data
What version of these packages are you using?
Please provide a link to a minimal reproduction of the issue.
https://stackblitz.com/edit/stackblitz-starters-xtvc7x?file=app%2Froutes%2F_index.tsx
Steps to Reproduce the Bug or Issue
The repro contains 3 examples:
Broky1
,Broky2
&Worky
. Switch thedefault
between them to see the different behaviors.Expected behavior
Since
resetAfterSubmit
is set, and theloader
is returning random data, I would expect the input to update its value on each validation Instead, the initial default value is keptScreenshots or Videos
No response
Platform
Additional context
No response