Form values
Initial values
In most cases you should set initialValues
:
setValues handler
With form.setValues
you can set all form values, for example you can set values after you have received a response from the backend API:
setValues partial
form.setValues
can also be used to set multiple values at once, payload will be shallow merged with current values state:
setFieldValue handler
form.setFieldValue
handler allows to set value of the field at given path:
reset handler
form.reset
handler sets values to initialValues
and clear all errors:
transformValues
Use transformValues
to transform values before they get submitted in onSubmit
handler.
For example, it can be used to merge several fields into one or to convert types:
Get values type
Get transformed values type
To get transformed values (output of transformValues) use TransformedValues
type.
It is useful when you want to create a custom submit function:
Set values type
By default, form values types will be inferred from initialValues
.
To avoid that, you can pass type to useForm
hook, this approach is useful when
types cannot be correctly inferred or when you want to provide more specific types: