1. Docs
  2. Forms
  3. TanStack Form

TanStack Form

Build forms with TanStack Form and Standard Schema validation.

This guide shows how to build forms using TanStack Form with Kanpeki's Field component and schema validation.

Demo

Approach

TanStack Form provides headless form state management. We combine it with:

  • Field components for layout and accessibility
  • TextField for automatic ID wiring between label, input, description, and error
  • Any Standard Schema library (Zod, Valibot, ArkType) for validation — no adapters needed
  • Real-time validation feedback

Anatomy

TextField is Kanpeki's React Aria behavior adapter. It automatically wires Field.Label, Field.Description, and Field.Error via aria-labelledby and aria-describedby. See the forms architecture for more.

Setup

Install dependencies

Replace zod with any Standard Schema-compliant library such as valibot or arktype — TanStack Form supports them all natively with no extra adapters.

Create a schema

Define your form shape with your schema library of choice. This example uses Zod:

Setup the form

Use useForm with your schema passed to validators:

Validation

Validation Modes

TanStack Form supports different validation strategies:

ModeDescription
onSubmitValidate on form submission
onChangeValidate on every change
onBlurValidate when field loses focus
onMountValidate immediately when field mounts

Displaying Errors

Use <Field.Error /> with the errors prop. It renders nothing when the array is empty, so no conditional render is needed:

Field Types

Input

Textarea

Select

Pass <Select.Root /> as the render prop on <Field.Root />. Use value and onChange for TanStack Form wiring.

Checkbox

For checkbox groups, use mode="array" and pass <Checkbox.Provider /> as the render prop on each <Field.Root />:

Switch

Submit Button State

Use <form.Subscribe /> to disable the submit button while submitting or when the form is invalid:

canSubmit is false when validation fails or a submission is already in flight. isSubmitting is true while onSubmit is pending.

Resetting the Form

Use form.reset() to reset to default values:

Array Fields

TanStack Form supports dynamic array fields with mode="array":

Array Helpers

MethodDescription
field.pushValue(item)Add item to end of array
field.removeValue(i)Remove item at index
field.insertValue(i)Insert item at index
field.swapValues(a,b)Swap items at indices
field.moveValue(from,to)Move item to new index
field.replaceValue(i,item)Replace item at index
field.clearValues()Remove all items

Linked Fields

When one field's validation depends on another (e.g. confirm password), use onChangeListenTo to re-run validation when the watched field changes: