-
-
Notifications
You must be signed in to change notification settings - Fork 566
Description
Describe the bug
I am encountering an issue where defining a defaultValue at the Field level takes precedence over the defaultValues defined in the useForm hook.
This becomes problematic when trying to follow the "Async Initial Values" documentation. When fetching async data to populate the form's defaultValues, the specific fields ignore that data if they have their own defaultValue prop set, effectively "locking" them to the hardcoded field default instead of updating with the async form data.
Is this expected behavior? If so, it seems to make the Async Initial Values workflow difficult if any fields have local defaults defined.
Your minimal, reproducible example
https://stackblitz.com/edit/tanstack-form-et3t1wkh?file=src%2Findex.tsx
Steps to reproduce
-
Initialize a form using useForm and provide a set of defaultValues (e.g., { firstName: 'Form Level Default' }).
-
Render a for that same key (firstName).
-
Add a defaultValue prop to that component (e.g., defaultValue="Field Level Default").
-
Render the component.
Expected behavior
I expected the Form-level defaultValues to take precedence, especially when they are populated (either synchronously or asynchronously). The Field-level defaultValue should ideally act as a fallback only if the Form-level value is undefined, or there should be a clear merge strategy documented.
Currently, the Field's local defaultValue overrides the Form's data, making it impossible to seed the field from the Form's state if the Field prop exists.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
OS: Mac
Chrome: Latest
TanStack Form adapter
react-form
TanStack Form version
Latest
TypeScript version
No response
Additional context
No response