werkbank
    Preparing search index...
    • Hook to handle input validation logic.

      Type Parameters

      • E extends ValidateElement

        The input element type.

      • Schema extends BaseSchema<any, any, any>

        The Valibot schema type.

      Parameters

      Returns {
          onBlur: FocusEventHandler<E>;
          onChange: ChangeEventHandler<E>;
          onInvalid: FormEventHandler<HTMLInputElement>;
          validate: (elm: E) => [any, ...any[]] | null | undefined;
      }

      Event handlers and a validate function.

      This hook integrates with the Form context and valibot schemas to validate input elements. It handles onChange, onBlur, and onInvalid events to trigger validation at appropriate times. It supports both immediate validation (after submit/blur) and lazy validation.

      const { onChange, onBlur } = useInputValidation({
      name: "email",
      validate: emailSchema,
      onChange: (e) => console.log(e.target.value)
      });
      return <input onChange={onChange} onBlur={onBlur} />;