use-form types
Form values types, generics, UseFormReturnType and TransformedValues
Package
Get values type
Form values type is inferred from initialValues. Use typeof form.values to reference it:
Set values type
Pass a type to useForm when it cannot be inferred from initialValues or when you need a more specific type:
TransformedValues type
TransformedValues is the type of transformValues output.
Use it to type a submit handler declared outside of form.onSubmit:
Set transformed values type
To set the transformed values type explicitly, pass a second type argument to useForm:
UseFormReturnType
Use UseFormReturnType to type form passed as a prop.
To share the form with many nested components, use form context instead:
FormPath type
FormPath<Values, Value> is a union of paths of form values with the given value type.
It is used to type components that render groups of fields:
FormErrors type
form.errors type is Record<string, React.ReactNode>, it is exported as FormErrors,
see Form errors.
Validation return types
form.validate, form.validateField and form.isValid return results directly with sync rules.
With any async rule, they return a Promise.
With schemaResolver, pass { sync: true } to get
sync return types.