Interface UseFormReturn<T>

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

Type Parameters

  • T

Hierarchy

  • UseFormReturn

Properties

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

field: (<K, E>(key: K, options?: FieldOptions<T, K>) => FieldReturn<E>)

Type declaration

    • <K, E>(key: K, options?: FieldOptions<T, K>): FieldReturn<E>
    • 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>

handleSubmit: ((e: FormEvent<HTMLFormElement>) => void)

Type declaration

    • (e: FormEvent<HTMLFormElement>): void
    • 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

isValid: boolean

Indicates whether the form is valid.

rawState: Partial<Record<keyof T, string | number | string[]>>

The current form data, before parsing.

setValue: (<K>(key: K, value: T[K]) => void)

Type declaration

    • <K>(key: K, value: T[K]): 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

setValues: ((values: Partial<T>) => void)

Type declaration

    • (values: Partial<T>): 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

state: Partial<T>

The current form data, after parsing.

Methods

Generated using TypeDoc