Nested fields

Every method of useForm takes a path. Use dots for objects and numbers for list items: user.email, tags.0.label. Errors use the same flat path, so the error of tags.0.label is form.errors['tags.0.label'].

Objects

const form = useForm({
  initialValues: { user: { name: '', email: '' } }
})

<Input {...form.getInputProps('user.name')} />

Lists

A rule object under a list key runs for every item. Add, remove and reorder items with the list methods. The errors of a list go away when you change it, because their positions change.

General

Add and remove items. Submit with an empty item to see its error.

APIs

ListMethods

NameDescriptionType
insertListItemadd an item, at the end when there is no index(path: string, item: unknown, index?: number) => void
removeListItemremove the item at the index(path: string, index: number) => void
reorderListItemmove an item from one index to another(path: string, indexes: { from: number; to: number }) => void
replaceListItemreplace the item at the index(path: string, index: number, item: unknown) => void
Edit this page on GitHub