form.Field options does not inherit from form options
Describe the bug
DefaultValue from form instatiation is not inherited by form.field options inside render function
Your minimal, reproducible example
Se code below
Steps to reproduce
const form = useForm({
defaultValues: {
name: 'Hello',
}
})
return (
<form.Field name="name" children={({ options }) => {
console.log(options.defaultValue)
return <View />
}} />
)
Will log undefined
Expected behavior
This value is only set when setting the defaultValue on the form.Field directly.
The defaultValue is retrievable via form.options.defaultValues?.name but I think the value should be Hello when accessing the options object in the render function on the form.Field
Or maybe the best solution would be that the value is
- defaultValue defined on the form.Field,
- If unassigned in 1, it inherits from the form instantiation
How often does this bug happen?
None
Screenshots or Videos
No response
Platform
React Native
TanStack Form adapter
react-form
TanStack Form version
0.33.0
TypeScript version
No response
Additional context
No response
@ljukas
You can access if you write like that
options.form.options.defaultValues
Thats the same workaround using form.options.defaultValues?.name, there still is the options.defaultValue which is the most obvious value to use but that also does not map to the defaultValue set for the form.
Thats the same workaround using
form.options.defaultValues?.name, there still is theoptions.defaultValuewhich is the most obvious value to use but that also does not map to the defaultValue set for the form.
we should access the default value via options.defaultValue. I don't know why it is empty
<form.Field name="name" children={({ options }) => {
console.log(options.defaultValue)
return <View />
}} />
This prints undefined correctly because there's no defaultValue passed as prop to the form.Field component.
form.options.defaultValues?.name is where you defined the default in this case.