Form

A native form element with consolidated error handling.

View as Markdown

Anatomy

Form is composed together with Field. Import the components and place them together:

Anatomy

API reference

errors

Errors

Name
Description

An object where the keys correspond to the name attribute of the form fields, and the values correspond to the error(s) related to that field.

Type

Errors

onClearErrors

function

Description

Event handler called when the errors object is cleared.

Type

((errors: Errors) => void)

className

string | function

Description

CSS class applied to the element, or a function that returns a class based on the component’s state.

Type

string | ((state: Form.State) => string)

render

ReactElement | function

Name
Description

Allows you to replace the component’s HTML element with a different tag, or compose it with another component.

Accepts a ReactElement or a function that returns the element to render.

Type

| ReactElement
| ((props: HTMLProps, state: Form.State) => ReactElement)

Examples

Using with Zod

When parsing the schema using schema.safeParse(), the result.error.flatten().fieldErrors data can be used to map the errors to each field’s name.