@tanstack/react-form. Familiarizing yourself with these concepts will help you better understand and work with the library.
Form Options
You can customize your form by creating configuration options with theformOptions function. These options can be shared between multiple forms.
Form Instance
A Form instance is an object that represents an individual form and provides methods and properties for working with the form. You create a Form instance using theuseForm hook.
Field
A Field represents a single form input element. Fields are created using theform.Field component provided by the Form instance.
If you run into ESLint issues with
children as props, configure your linting rules:Field State
Each field has its own state, which includes its current value, validation status, error messages, and other metadata.Field Metadata States
There are several states in the metadata that track user interaction:- isTouched:
trueonce the user changes or blurs the field - isDirty:
trueonce the field’s value is changed, even if reverted to default (opposite ofisPristine) - isPristine:
trueuntil the user changes the field’s value (opposite ofisDirty) - isBlurred:
trueonce the field loses focus - isDefaultValue:
truewhen the field’s current value is the default value
Understanding ‘isDirty’ in Different Libraries
- Non-Persistent (RHF, Formik)
- Persistent (TanStack Form)
A field is ‘dirty’ if its value differs from the default. Reverting to the default value makes it ‘clean’ again.
Field API
The Field API is an object passed to the render prop function when creating a field. It provides methods for working with the field’s state.Validation
TanStack Form provides both synchronous and asynchronous validation out of the box.Validation with Schema Libraries
TanStack Form supports the Standard Schema specification:- Zod
- Valibot
- Yup
- ArkType
Reactivity
TanStack Form offers various ways to subscribe to form and field state changes using theuseStore hook and the form.Subscribe component.
Listeners
Listeners allow you to react to specific triggers and dispatch side effects.Array Fields
Array fields allow you to manage a list of values within a form. Use themode="array" prop to create an array field.
Reset Buttons
When using reset buttons, prevent the default HTML reset behavior:type="button":