Interface UseFormReturn<T>

Return value of the useForm hook. See each property for more information.

Type Parameters

  • T

Hierarchy

  • UseFormReturn

Properties

dirty: Partial<Record<keyof T, boolean>>

A mapping of all the fields that have been modified by the user.

If a field is dirty, its key will be true in this object.

errors: Partial<Record<keyof T, ErrorMessage>>

A mapping of the error messages given for each field. Each property is the name of the field and the value is the error message, if any.

If there is no error, the value will be undefined.

See

ErrorMessage

isValid: boolean

Indicates whether the form is valid.

rawState: Partial<Record<keyof T, unknown>>

The current form data, before parsing.

state: Partial<T>

The current form data, after parsing.

Methods

  • Register a field input named key to the form. This will return props that should be injected into the input. See each of the options for more information.

    Returns

    Props that should be injected into the input.

    See

    FieldOptions

    Type Parameters

    • K extends string | number | symbol

      The key of the field in the form state.

    • E

      The type of the input element.

    Parameters

    • key: K

      The name of the field.

    • Optional options: FieldOptions<T, K>

      Options for the field.

    Returns FieldReturn<E>

  • A callback that will submit the form. This will also call onSubmit if it was provided. You should inject this into the form's onSubmit prop.

    Parameters

    • e: FormEvent<HTMLFormElement>

      The form submit event.

    Returns void

  • Set a single field. This will cause the form to re-render.

    See

    UseFormReturn.setValues for setting multiple values at once

    Type Parameters

    • K extends string | number | symbol

    Parameters

    • key: K

      The name of the field.

    • value: T[K]

      The value to set.

    Returns void

  • Set multiple fields at once. This will cause the form to re-render.

    See

    UseFormReturn.setValue for setting a single value

    Parameters

    • values: Partial<T>

      The values to set, as an object of { field: value }.

    Returns void

Generated using TypeDoc