Migrating from v1
This guide covers changes to field state, validation, subscriptions, and composition when migrating React apps from TanStack Form v1 to v2.
Quick checklist#
- Update field render props from field.state.value and field.state.meta to field.value and field.meta.
- defaultValues are now a required property.
- Move field-level defaultValue props into form-level defaultValues.
- Remove field-level defaultMeta props. Use validators, triggers: ['mount'], and errorVisibility to control initial validation and error visibility.
- Change validation from objects keyed by events like { onChange, onBlur } to arrays of validator objects with run and triggers.
- Change async validator debounce options such as onChangeAsyncDebounceMs to triggerDebounceMs on the validator object.
- Replace onChangeListenTo / onBlurListenTo with watchFields on validators or listeners for validation that depends on other fields.
- Replace mode="array" fields with form.ArrayField.
- Rename form.moveFieldValues to form.moveFieldValue, and replace removed form methods such as setFieldMeta and validateField as described in Removed and renamed form methods.
- Read errors from field.errors, group.state.errors, and form.state.errors as validation issue objects. Use error.message when rendering text.
- In form- and group-level validators, build routed errors with createErrorMap(...) and return the map directly.
- Return errors from onSubmit with createErrorMap(...), createValidationError(...), or parseIssues(...) when a submit handler needs to report server validation errors.
- Replace the deprecated useStore hook with useSelector.
- Subscribe to form.atom and field.atom instead of form.store and field.store.
- Replace withForm components with plain components that accept a form prop typed as ReactFormType<typeof formOpts>.
- Replace useFormGroup with form.FormGroup for scoped sections of the same form.
- Replace withFieldGroup with defineFieldGroup(...).bindComponent(...) for reusable groups of fields that map virtual field names to paths in each form.
- Upgrade Vue to version 3.6 or newer when using the Vue adapter. Form Composition relies on behavior introduced in Vue 3.6.
- Update CommonJS integrations to consume ESM. The v2 packages do not publish a CommonJS build and require Node.js 18 or newer.
- Upgrade React to version 18 or newer. The v2 React adapter no longer supports React 17.
React version#
The v2 React adapter supports React 18 and 19. React 17 is no longer supported, so upgrade react, react-dom, and their corresponding type packages before migrating. If you imported CrossVersionReactNode from @tanstack/react-form, import ReactNode from react instead.
Vue version#
The v2 Vue adapter requires Vue 3.6 or newer. At the time of writing, Vue 3.6 has not yet been released as stable and is available as a release candidate. We hope Vue 3.6 will be stable by the time TanStack Form v2 becomes stable.
Form Composition relies on Vue 3.6 behavior. Requiring it from the start avoids raising the minimum Vue version in a later v2 release to support Form Composition.
Package format#
The v2 core, framework, devtools, and server-adapter packages publish only ESM exports and require Node.js 18 or newer. Prefer import / export syntax, use dynamic import() when consuming them from CommonJS, and make sure any Node-based test, SSR, or build tooling can load ESM dependencies. There is no CommonJS build or require export.
Basic fields#
In v2, read subscribed values and metadata directly from the field render prop:
// v1
<form.Field name="firstName">
{(field) => (
<input
name={field.name}
value={field.state.value}
onBlur={field.handleBlur}
onChange={(event) => field.handleChange(event.target.value)}
/>
)}
</form.Field>// v2
<form.Field name="firstName">
{(field) => (
<input
name={field.name}
value={field.value}
onBlur={field.handleBlur}
onChange={(event) => field.handleChange(event.target.value)}
aria-invalid={field.meta.isInvalid}
/>
)}
</form.Field>Update metadata and error reads as well:
// v1
field.state.value
field.state.meta.isTouched
field.state.meta.isValid
field.state.meta.errors.join(',')// v2
field.value
field.meta.isTouched
field.meta.isValid
field.errors.map((error) => error.message).join(',')v2 also exposes field.meta.isInvalid, the inverse of isValid, for attributes such as aria-invalid.
Defaults and initial meta#
In v1, a form could rely on field-level defaultValue props:
// v1
const form = useForm({
defaultValues: {} as Person,
})
<form.Field name="firstName" defaultValue="">
{(field) => <input value={field.state.value} />}
</form.Field>In v2, defaultValues are required on the form and are the only place to define initial values:
// v2
const form = useForm({
defaultValues: {
firstName: '',
lastName: '',
},
})
<form.Field name="firstName">
{(field) => <input value={field.value} />}
</form.Field><form.Field defaultMeta={...}> was also removed. To replace defaultMeta={{ isTouched: true }} for showing errors immediately, use mount validation and errorVisibility:
// v2
const form = useForm({
defaultValues: {
firstName: '',
},
})
<form.Field
name="firstName"
validators={[
{
triggers: ['mount', 'change', 'blur'],
run: ({ value }) => (value ? undefined : 'First name is required'),
},
]}
>
{(field) => (
<>
<input
value={field.value}
onBlur={field.handleBlur}
onChange={(event) => field.handleChange(event.target.value)}
/>
{field.errors.map((error) => (
<p key={error.message}>{error.message}</p>
))}
</>
)}
</form.Field>If a field should validate on mount but its errors should remain hidden until the user blurs it or tries to submit, use a form-level policy such as errorVisibility: ({ fieldState, state }) => fieldState.meta.isBlurred || state.submissionAttempts > 0 instead.
Validators#
v1 validators are keyed by event names:
// v1
<form.Field
name="firstName"
validators={{
onChange: ({ value }) =>
!value
? 'A first name is required'
: value.length < 3
? 'First name must be at least 3 characters'
: undefined,
onChangeAsyncDebounceMs: 500,
onChangeAsync: async ({ value }) => {
await checkName(value)
return value.includes('error')
? 'No "error" allowed in first name'
: undefined
},
}}
/>In v2, validators is an ordered array. Each validator has a run function or Standard Schema, a triggers list, and options for behavior such as debouncing or skipping validation after an earlier failure:
// v2
<form.Field
name="firstName"
validators={[
{
run: ({ value }) => {
if (value.length === 0) return 'A first name is required'
if (value.length < 3) return 'First name is too short'
},
triggers: ['change', 'blur'],
},
{
run: async ({ value }) => {
await checkName(value)
return value.toLowerCase().includes('error')
? 'No "error" allowed in first name'
: undefined
},
triggers: ['change'],
triggerDebounceMs: 500,
bailIfInvalid: true,
},
]}
/>The main validator options map as follows:
| v1 | v2 |
|---|---|
| validators.onMount | validator with triggers: ['mount'] |
| validators.onChange | validator with triggers: ['change'] |
| validators.onBlur | validator with triggers: ['blur'] |
| validators.onSubmit | validator with triggers: []; validators run on submission by default |
| onChangeAsync | async run with triggers: ['change'] |
| onChangeAsyncDebounceMs | triggerDebounceMs |
| onChangeListenTo / onBlurListenTo | watchFields |
| validationLogic: revalidateLogic() | explicit triggers, when, skipOnSubmit, and bailIfInvalid rules |
Submission is separate from the triggers list: every validator runs during submission by default. An empty triggers: [] therefore disables mount, change, and blur validation while keeping submit validation. Set skipOnSubmit: true when a validator must not run during client submission; do not add 'submit' to triggers.
triggers can contain strings or configuration objects. Use an object with when to run a validator only for changes that meet a condition:
validators={[
{
triggers: [
{
trigger: 'change',
when: ({ value }) => Boolean(value),
},
],
watchFields: ['startDate'],
run: ({ value, formApi }) => {
const startDate = formApi.getFieldValue('startDate')
if (value < startDate) return 'End date must be after the start date'
},
},
]}The when, skipOnSubmit, and triggerDebounceMs callbacks receive scope, value, and formApi. The value belongs to the form, group, or field being validated. Field callbacks receive that field as fieldApi, while group callbacks also receive groupApi. For form and group callbacks, an optional fieldApi is the field that triggered validation. Keep these callbacks synchronous and free of side effects.
For form, group, and field validators, triggerDebounceMs accepts a delay in milliseconds or a callback that returns one. The callback can change the delay based on form state, such as removing the delay after a submission attempt:
const form = useForm({
defaultValues: {
firstName: '',
},
validators: [
{
triggers: ['change', 'blur'],
triggerDebounceMs: ({ formApi }) =>
formApi.state.submissionAttempts > 0 ? 0 : 300,
run: ({ value }) =>
value.firstName ? undefined : 'First name is required',
},
],
})Repeated matching events restart the delay for that validator. Debouncing applies to change and blur validation, including synchronous validators. Mount, server, and submission validation run without a debounce delay.
Use createValidator(...) to reuse trigger and validation options with different validator functions or schemas while preserving their inferred types:
import { createValidator } from '@tanstack/react-form'
const validateAfterSubmit = createValidator({
triggers: [
{
trigger: 'change',
when: ({ groupApi, formApi }) =>
(groupApi?.state.submissionAttempts ??
formApi.state.submissionAttempts) > 0,
},
],
})
const validators = [validateAfterSubmit(schema)]See Form and Field Validation for more on validation timing and options.
Standard schemas#
v1 accepted Standard Schemas in validators keyed by events:
// v1
useForm({
defaultValues,
validators: {
onChange: schema,
},
})In v2, pass schemas as run values inside the validators array:
// v2
useForm({
defaultValues,
validators: [
{
run: schema,
triggers: ['change'],
},
],
})The form's value remains the editable input. When a Standard Schema validator runs successfully during submission, its parsed output is available in onSubmit at the corresponding validatorOutputs index. Form and group validator functions can return createOutput(data) to provide data at their index; createOutput is supplied to run. Successful validators that return no output contribute undefined. Validators with literal skipOnSubmit: true are skipped during submission, and their slots are typed as undefined. Use the parsed entry when an endpoint expects the schema's output type.
To infer form types from a schema, pass the schema first and the options second. formOptions.strictSchema(...) uses the schema input as the form shape, while formOptions.looseSchema(...) permits editable nullish defaults and combines them with the schema shape. These option helpers only affect types; the validators still perform the runtime parsing.
When calling a schema manually in a field validator, return its issue array directly, such as result.error.issues from a failed schema.safeParse(...). These issues belong to the field being validated. In a form or group validator, return parseIssues(...) to route issues to the form and fields by their paths. In onSubmit, parseIssues(...) produces a branded submit validation result.
Errors and submit results#
Replace field.state.meta.errors with field.errors. For form groups, read group.state.errors; for the form, read form.state.errors. These collections are arrays of validation issue objects, so render error.message:
function FieldError({ field }: { field: AnyFieldApi }) {
return (
<small role={field.meta.isInvalid ? 'alert' : undefined} aria-live="polite">
{field.errors.map((error) => error.message).join('\n')}
</small>
)
}Form- and group-level validators can route errors to the form and individual fields. Build a map with the createErrorMap supplied to run, then return the map itself:
const form = useForm({
defaultValues: {
firstName: '',
},
validators: [
{
triggers: ['change'],
run: ({ value, createErrorMap }) => {
const errors = createErrorMap()
if (!value.firstName.trim()) {
errors.addFormError('Please correct the highlighted fields')
errors.addFieldError('firstName', 'First name is required')
}
return errors
},
},
],
})createErrorMap also accepts an initial { form, fields } object containing strings, issue objects, or arrays of errors. The map stores errors in arrays; use addFormError and addFieldError to add errors. An empty returned map is treated as a valid result.
Submit handlers can now return a typed validation result. To report validation errors from an endpoint, return a map from the submit context's createErrorMap:
const form = useForm({
defaultValues: {
firstName: '',
lastName: '',
},
onSubmit: async ({ value, createErrorMap }) => {
const result = await saveUser(value)
if (!result.ok) {
return createErrorMap({
form: 'Could not save user',
fields: {
firstName: 'Name already exists',
lastName: 'Name already exists',
},
})
}
return null
},
})Use createValidationError(...) to wrap existing error messages, issue objects, error arrays, or error maps. Use parseIssues(...) for Standard Schema issues. Return the helper's result from onSubmit to report validation errors.
form.handleSubmit() resolves to an array of validation issues and error maps for that submission attempt. An empty array means no validation errors were reported. It does not guarantee successful submission: canceled attempts can resolve with [], and exceptions suppressed through preventThrow() can also leave the array empty.
Exceptions from validators or onSubmit reject handleSubmit() by default. onSubmitInvalid receives the failure's reason, source, and error; call its preventThrow() to suppress the submission exception. The attempt remains unsuccessful, and the exception does not become a validation error. Exceptions from onSubmitInvalid itself still reject handleSubmit().
Selectors and atoms#
v1 re-exported useStore from @tanstack/react-store, but that usage was deprecated before v2. In v2, use useSelector and subscribe to atoms:
// v1
import { useStore } from '@tanstack/react-store'
const errors = useStore(form.store, (state) => state.errors)
const fieldErrors = useStore(field.store, (state) => state.meta.errors)// v2
import { useSelector } from '@tanstack/react-form'
const errors = useSelector(form.atom, (state) => state.errors)
const fieldErrors = useSelector(field.atom, (state) => state.meta.errors)Use useSelector with field-group atoms as well:
const values = useSelector(fields.atom, (values) => values)Arrays#
v1 represented array fields with mode="array" and exposed array helpers from the field render prop:
// v1
<form.Field name="people" mode="array">
{(field) => (
<>
{field.state.value.map((_, index) => (
<form.Field key={index} name={`people[${index}].name`}>
{(subField) => (
<input
value={subField.state.value}
onChange={(event) => subField.handleChange(event.target.value)}
/>
)}
</form.Field>
))}
<button
type="button"
onClick={() => field.pushValue({ name: '', age: 0 })}
>
Add person
</button>
</>
)}
</form.Field>Replace <form.Field mode="array"> with form.ArrayField:
// v2
<form.ArrayField name="people">
{(array) => (
<>
{array.value.map((_, index) => (
<form.Field key={index} name={`people[${index}].name`}>
{(field) => (
<input
name={field.name}
value={field.value}
onBlur={field.handleBlur}
onChange={(event) => field.handleChange(event.target.value)}
/>
)}
</form.Field>
))}
<button
type="button"
onClick={() => array.pushValue({ name: '', age: 0 })}
>
Add person
</button>
</>
)}
</form.ArrayField>For array methods called on a regular field API, switch to the ArrayField render prop or a form method that takes the field path:
form.pushFieldValue('people', { name: '', age: 0 })ArrayField lets the array container rerender when its structure changes without rerendering the whole list for every item value change.
See Arrays for usage and examples for each framework.
Removed and renamed form methods#
Read metadata from the field API and return errors from validators or submit handlers. The internal field-registry helpers have no replacement.
| v1 | v2 |
|---|---|
| moveFieldValues(name, from, to) | moveFieldValue(name, from, to) |
| setFieldMeta(name, updater) | setFieldValue update options, handleSubmit(), or errorVisibility |
| getFieldMeta(name) | field.meta |
| resetFieldMeta(...) | resetField(name), field.reset(), or reset(form.state.values, { updateDefaultValues: false }) |
| validateField(name, cause) | validator triggers and watchFields |
| validateAllFields(cause) | handleSubmit() |
| validateArrayFieldsStartingFrom(...) | array methods run change validation unless causeValidation: false |
| validate(cause) | validate('change' | 'blur'), which runs form-level validators only |
| getAllErrors() | form.state.errors, field.errors, form.state.isValid, or the handleSubmit() result |
| setErrorMap(errorMap) | errors returned from validators, onSubmit error helpers, or serverState |
| deleteField(name) | removeFieldValue / filterFieldValues for array items, setFieldValue on the parent object |
| getFieldInfo(name) | none; it exposed internal field registration |
| parseValuesWithSchema(schema) and its Async variant | a schema validator plus validatorOutputs in onSubmit, or call the schema directly |
| getFormGroupMeta(name) | group.state from form.FormGroup |
Field metadata#
In v1, setFieldMeta could mark a field as touched after setting its value programmatically. In v2, metadata is derived from updates. Pass FieldUpdateOptions to setFieldValue, the array methods, or field.handleChange to control what an update marks:
// v1
form.setFieldValue('firstName', 'Ada', {
dontUpdateMeta: true,
dontValidate: true,
})
form.setFieldMeta('firstName', (prev) => ({ ...prev, isTouched: true }))// v2
form.setFieldValue('firstName', 'Ada', {
markAsTouched: true,
markAsDirty: false,
causeValidation: false,
})| v1 update option | v2 update option |
|---|---|
| dontUpdateMeta | markAsTouched: false, markAsDirty: false |
| dontValidate | causeValidation: false |
| dontRunListeners | none |
Call form.handleSubmit() to mark all registered fields as touched before showing errors. To show errors without marking fields as touched, configure errorVisibility.
Read metadata through field.meta in a render prop or useSelector(field.atom, (state) => state.meta). The form API does not look up metadata by path.
Use form.resetField(name) or field.reset() to reset one field's value and metadata. To clear every field's metadata while keeping the current values and defaults, pass the current values to reset with updateDefaultValues: false:
form.reset(form.state.values, { updateDefaultValues: false })This also clears form-level errors, submission state, and dirty history.
On-demand validation#
v2 has no public method for validating one or all fields outside submission. Configure when field validators run instead:
- Use triggers to choose the events that run a validator.
- Use watchFields to rerun a validator when another field changes, which covers most v1 validateField calls made from another field's onChange.
- Call form.handleSubmit() to validate every field and the form together. Unlike validateAllFields, it also calls onSubmit when validation passes. It resolves to the reported validation errors. An empty array can also come from a canceled attempt or a suppressed exception; see Errors and submit results.
form.validate('change') and form.validate('blur') run only form-level validators, so they cannot replace validateField or validateAllFields.
Errors#
v2 has no form method for setting error maps directly. Return errors from a validator, or from onSubmit with its error helpers as shown in Errors and submit results. For server-rendered errors, pass serverState to useForm.
form.state.errors holds only form-level errors. Read errors routed to fields from field.errors. Use form.state.isValid to check both levels at once.
Schemas#
parseValuesWithSchema checked the current values against a schema without storing errors. To keep that behavior, call the schema yourself:
const result = await schema['~standard'].validate(form.state.values)
if (result.issues) {
// handle issues
}To validate with the schema and use its parsed output, add it to validators and read validatorOutputs in onSubmit, as described in Standard schemas.
Shared form options#
withForm was removed. Use formOptions(...) to share options and derive the form types for extracted components:
import { formOptions } from '@tanstack/react-form'
export const sharedFormOptions = formOptions({
defaultValues: {
firstName: '',
lastName: '',
address: {
street: '',
country: '',
},
},
})
const form = useForm({
...sharedFormOptions,
onSubmit: ({ value }) => {
console.log(value)
},
})When typing extracted components, prefer the v2 public types covered in Splitting forms:
import type { AnyReactFormApi, FieldWithValue } from '@tanstack/react-form'
function StringField({ field }: { field: FieldWithValue<string> }) {
return (
<input
value={field.value}
onChange={(event) => field.handleChange(event.target.value)}
/>
)
}
function SubmitButton({ form }: { form: AnyReactFormApi }) {
return (
<form.Subscribe selector={(state) => [state.canSubmit, state.isSubmitting]}>
{([canSubmit, isSubmitting]) => (
<button type="submit" disabled={!canSubmit || isSubmitting}>
{isSubmitting ? '...' : 'Submit'}
</button>
)}
</form.Subscribe>
)
}AnyReactFormApi and FieldWithValue<T> omit unrelated type details for generic UI components. Use ReactFormType<typeof formOpts> when a component needs the data and field-path types inferred from the options. Options created with appFormOptions also retain their app component map. Submit error types may widen when shared options omit onSubmit so it can be supplied later. Prefer these aliases over writing the full FormApi or FieldApi generic parameter lists in application components.
For components that previously used withForm, pass the form API explicitly and type it from the same options object:
// v1
const AddressFields = withForm({
defaultValues: {
address: {
street: '',
country: '',
},
},
render: ({ form }) => (
<>
<form.Field name="address.street">{/* ... */}</form.Field>
<form.Field name="address.country">{/* ... */}</form.Field>
</>
),
})// v2
import { formOptions } from '@tanstack/react-form'
import type { ReactFormType } from '@tanstack/react-form'
export const profileFormOptions = formOptions({
defaultValues: {
address: {
street: '',
country: '',
},
},
})
interface AddressFieldsProps {
form: ReactFormType<typeof profileFormOptions>
}
function AddressFields({ form }: AddressFieldsProps) {
return (
<>
<form.Field name="address.street">{/* ... */}</form.Field>
<form.Field name="address.country">{/* ... */}</form.Field>
</>
)
}Form groups and field groups#
Replace useFormGroup with form.FormGroup for multi-step forms and validation scoped to a section of one form:
<form.FormGroup name="guestDetails" onSubmit={() => goToNextStep()}>
{(group) => (
<>
<group.Field name="name">
{(field) => (
<input
value={field.value}
onChange={(event) => field.handleChange(event.target.value)}
/>
)}
</group.Field>
<button type="button" onClick={() => group.handleSubmit()}>
Continue
</button>
</>
)}
</form.FormGroup>Field names used through the group API are scoped to the group. name="name" becomes guestDetails.name, group.ArrayField name="guests" becomes guestDetails.guests, and watched fields are scoped the same way.
group.handleSubmit() validates the group and its fields, then calls the group's onSubmit or onSubmitInvalid. It resolves to an error array, and group.state.errors is an array. Because form.handleSubmit() does not run group validators, include any rules required for final submission in the form's validators as well.
For a field inside a mounted group, scalar state exposed to errorVisibility (such as submissionAttempts and isDirty) is scoped to the nearest group. The callback's values and errors remain form-wide.
Replace withFieldGroup with defineFieldGroup(...) for reusable groups of fields. It lets a component use virtual field names that each parent form maps to its own paths:
import { defineFieldGroup } from '@tanstack/react-form'
const rangeFieldGroup = defineFieldGroup(({ strict }) => ({
lower: strict<string>(),
upper: strict<string>(),
}))
function RangeFieldsImpl({
fields,
}: {
fields: typeof rangeFieldGroup.fields
}) {
return (
<>
<fields.Field name="lower">
{(field) => (
<input
value={field.value}
onChange={(event) => field.handleChange(event.target.value)}
/>
)}
</fields.Field>
<fields.Field
name="upper"
validators={[
{
triggers: ['change'],
watchFields: ['lower'],
run: ({ value }) => {
const lower = fields.getFieldValue('lower')
if (Number(value) < Number(lower)) {
return 'Upper bound must be greater than lower bound'
}
},
},
]}
>
{(field) => (
<input
value={field.value}
onChange={(event) => field.handleChange(event.target.value)}
/>
)}
</fields.Field>
</>
)
}
export const RangeFields = rangeFieldGroup.bindComponent(
RangeFieldsImpl,
'fields',
)Pass the field-path mapping when rendering the component:
<RangeFields
form={form}
fields={{
lower: 'minPrice',
upper: 'maxPrice',
}}
/>For app form components from createFormHook, wrap components that receive a field API prop with getFormHookHelpers(). Use defineAppFieldGroup to define field groups with those app components:
import { createFormHook, getFormHookHelpers } from '@tanstack/react-form'
const { fieldComponent } = getFormHookHelpers()
const AppTextField = fieldComponent.strict()({
component: StringField,
replaceProperty: 'field',
})
const { appFormOptions, useAppForm, defineAppFieldGroup } = createFormHook({
fieldComponents: {
TextField: AppTextField,
},
formComponents: {},
})
const contactFieldGroup = defineAppFieldGroup(({ strict }) => ({
name: strict<string>(),
}))See Build Reusable React Form Sections with Field Groups for the full pattern.
Listeners#
Replace listener objects keyed by events with arrays of objects containing run, triggers, and an optional triggerDebounceMs, as with validators. A trigger can be a string or { trigger, when }, and triggerDebounceMs can be a number or a callback. Form listeners support change, blur, submit, mount, and reset; field listeners additionally support unmount.
// v2
<form.Field
name="amount"
listeners={[
{
triggers: ['blur'],
run: ({ value, fieldApi }) => {
fieldApi.handleChange(Number(value).toFixed(2))
},
},
]}
/>For field listeners that watch other fields, put those fields in watchFields. In form.FormGroup and field-group-bound components, watchFields uses the scoped or virtual field names and v2 resolves them to the concrete form paths. Form-level listeners receive events from fields as well as the form. The optional triggerFieldApi identifies the source field for field changes and blurs. It is absent for events from the form itself, such as mount, reset, and submit.
Server and framework integrations#
The TanStack Start and Next.js adapters use shared form options for server validation:
- Get createServerValidate directly from start() in @tanstack/react-form-start or next(...) in @tanstack/react-form-nextjs.
- Return the createErrorMap() map directly from framework/server validators when routing form and field errors.
- Combine triggers: ['server'] with skipOnSubmit: true for a form validator that must run only on the server. Server-triggered validators otherwise still run during client submission because submission is enabled by default.
- The Next.js adapter, and the Start adapter when no callback override is supplied, resolve to { success: true, values, validatorOutputs } or { success: false, serverState }. Pass the failure's serverState back to useForm({ ...formOpts, serverState }) on the client.
- @tanstack/react-form-remix was removed.
Configure the Start adapter separately from the shared form options:
import { start } from '@tanstack/react-form-start'
const { createServerValidate } = start()
const serverValidate = createServerValidate(formOpts)Call the Start validator with { formData }. The Next.js validator accepts FormData directly; configure decoding such as numeric fields through next({ info: { numbers: ['age'] } }).
In formOpts, a server-only validator returns its routed error map directly:
{
triggers: ['server'],
skipOnSubmit: true,
run: ({ value, createErrorMap }) => {
const errors = createErrorMap()
if (value.age < 13) {
errors.addFieldError('age', 'You must be at least 13')
}
return errors
},
}On the client, read values from field.value and errors from field.errors:
<form.Field name="age">
{(field) => (
<>
<input
name={field.name}
value={field.value}
onBlur={field.handleBlur}
onChange={(event) => field.handleChange(Number(event.target.value))}
/>
{field.errors.map((error) => (
<div key={error.message} role="alert">
{error.message}
</div>
))}
</>
)}
</form.Field>Migration order for an app#
- Update CommonJS integrations and tooling to load ESM packages.
- Move every field-level defaultValue into form-level defaultValues and remove defaultMeta.
- Update field render props from field.state.* to field.value, field.meta, and field.errors.
- Replace useStore(...store...) with useSelector(...atom...).
- Convert validators and listeners to arrays and check which validators should run on submission.
- Replace mode="array" fields with form.ArrayField.
- Return createErrorMap(...) directly from form, group, and server validators, and report endpoint validation errors from onSubmit with createErrorMap, createValidationError, or parseIssues.
- Replace withForm with components that accept a form prop typed as ReactFormType<typeof formOpts>, useFormGroup with form.FormGroup, and withFieldGroup with defineFieldGroup(...).bindComponent(...).
- Rerun your app's React integration tests for validation timing, field rerenders, groups, server errors passed to the client, and array mutations. v2 changes behavior in these areas.