#How to update defaultValues?

8 messages · Page 1 of 1 (latest)

obsidian ivy
#

I have two components: one of them is a list of entries, and the other one is details of the selected entry. It accepts id of the selected entry as a prop, loads existing values with TSQuery, and uses them as defaultValues.

Simple reproduction:
https://stackblitz.com/edit/vitejs-vite-ainjeqwv?file=src%2FApp.tsx

I change locale in the details component from default ("Ja") to different one ("En"), then switch to another entry in the list component.
The locale value resets to default one, "Ja", (because of form.reset()), but somehow, the fields inside the <form.Subscribe> are now having values of the previous locale ("En").
i.e. the locale field shows the correct, default locale (Ja), but values of the dependent fields are actually are from different locale - the locale that was previously selected in the previous entry (En).

Next generation frontend tooling. It's fast!

inner river
#

defaultValues don‘t update after the form has been touched. The idea is that a user‘s changed values shouldn‘t be deleted afterwards

#

if you want to force changes (ditch all of the user‘s data), you could use a component key of the selected id. That forces the whole component to be recomputed, including resetting the form

#

you‘ll probably want the useQuery outside of it in that case, but hopefully that makes sense

obsidian ivy
inner river
inner river
#

if you have the useQuery in the parent, you could keep previous data on refetches to make the changes visually unnoticeable

obsidian ivy