TanStackT
TanStack8mo ago
21 replies
developed-pink

form defaultValues doesn't clear with initial data retrieved

hey all! posting my first question here in a confusing situation i'm in. I use tanstack query to fetch data from an endpoint, and tanstackform to handle em. I've a two dropdown screen, in which the second dropdown is clearable/deletable by users but i'm unable to reach that state which falls back to form.defaultValues instead of users able to remove its node completely.

What happens is that if I commented this code out
if (!country) return;
it deletes the value from the dropdown, but i'm left with my object like this:
[{"country": "AD","verId": "1"},{"country": "","verId": ""}]

and if I didn't, i'm unable to remove anything, anytimg i try to click on the delete button, it doesn't do anything and i'm left with the default values.

const form = useForm({defaultValues: {taxResidencies: userData?.taxResidencies ?? ([] as TaxResidency[]),},onSubmit: async ({ value }) => {}});
Was this page helpful?