Function useFormManager

  • Custom hook for managing form state and validation. Compatible with both React and React Native, this hook provides state management for form values and errors, customizable field validation, and event handlers for input actions.

    Type Parameters

    • TFormValues

      The structure of the form values, e.g., { email: string; password: string; }

    Parameters

    • initialValues: TFormValues

      The initial values for form fields

    • onSubmit: ((values: TFormValues) => void)

      Callback function to execute on form submission, called with current form values

        • (values): void
        • Parameters

          Returns void

    • validators: Partial<Record<keyof TFormValues, Validator<TFormValues[keyof TFormValues]>>> = {}

      An optional object with validators for each field; keys should match field names

    Returns UseFormManagerReturn<TFormValues>

    An object containing form state, input handlers, and utilities

    const { formState, handleChange, handleSubmit, getInputProps } = useFormManager(
    { email: '', password: '' },
    (values) => console.log(values),
    { email: (value) => !value ? 'Required' : null }
    );