interface FormContextProps {
    errors: Record<string, string>;
    isValid: boolean;
    setErrors: Dispatch<SetStateAction<Record<string, string>>>;
    setValues: Dispatch<SetStateAction<Record<string, string>>>;
    touched: Record<string, boolean>;
    values: Record<string, string>;
    getError(fieldId: string): string;
    getValue(fieldId: string): string;
    isTouched(fieldId: string): boolean;
    setError(fieldId: string, error: string): void;
    setTouched(fieldId: string, isTouched: boolean): void;
    setValidator(fieldId: string, validate: ((value: string) => string)): void;
    setValue(fieldId: string, value: string): void;
    validate(): Record<string, string>;
}

Properties

errors: Record<string, string>

Record of errors for all fieldIds

isValid: boolean

Flag to determine the overall validity. True if the record of errors is empty.

setErrors: Dispatch<SetStateAction<Record<string, string>>>

Set multiple errors within the managed record of errors

setValues: Dispatch<SetStateAction<Record<string, string>>>

Set multiple values within the managed record of values

touched: Record<string, boolean>

Record of touched state for all fieldIds

values: Record<string, string>

Record of values for all fieldIds

Methods

  • Get the error message for a given fieldId

    Parameters

    • fieldId: string

    Returns string

  • Get the value for a given fieldId

    Parameters

    • fieldId: string

    Returns string

  • Used to determine touched state for a given fieldId

    Parameters

    • fieldId: string

    Returns boolean

  • Set the error message for a given fieldId

    Parameters

    • fieldId: string
    • error: string

    Returns void

  • Used to update the touched state for a given fieldId

    Parameters

    • fieldId: string
    • isTouched: boolean

    Returns void

  • Set a validator for a specific fieldId

    Parameters

    • fieldId: string
    • validate: ((value: string) => string)
        • (value): string
        • Parameters

          • value: string

          Returns string

    Returns void

  • Set the value for a given fieldId

    Parameters

    • fieldId: string
    • value: string

    Returns void

  • Triggers all fieldId-specific validators

    Returns Record<string, string>