errorsOf

Turns the errors of a field into the texts a widget renders.

Turns the errors of a field into the texts a widget renders.

An error is either a string or an object with a message, such as an issue of a Standard Schema. Errors without text are left out, and a text that several validators report appears once, where it first occurs. A field's errors stay readable with TanStack's disableErrorFlat option.

Type parameters

NameDescription
TValueThe value type of the field.

Parameters

NameDescription
fieldThe field the widget renders.

Returns

The distinct texts of the field's current errors, in order; empty when there are none.

Example

const TextField = ({ field }: FieldOf<string>) => (
  <>
    <input value={field.state.value} onChange={(event) => field.handleChange(event.target.value)} />
    <p>{errorsOf(field).join(' ')}</p>
  </>
)

See also