UNPKG

@shopify/react-form

Version:

Manage react forms tersely and safely-typed with no magic using React hooks.

20 lines (19 loc) 1.18 kB
/// <reference types="react" /> import { FormMapping, SubmitHandler, SubmitResult, FieldBag, FormError } from '../types'; export declare function useSubmit<T extends FieldBag>(onSubmit: SubmitHandler<FormMapping<T, "value">> | undefined, fieldBag: T): { submit: (event?: import("react").FormEvent<Element> | undefined) => Promise<void>; submitting: boolean; errors: FormError[]; setErrors: import("react").Dispatch<import("react").SetStateAction<FormError[]>>; }; /** * A convenience function for `onSubmit` callbacks returning values to `useSubmit` or `useForm`. * @return Returns a `SubmitResult` representing your successful form submission. */ export declare function submitSuccess(): SubmitResult; /** * A convenience function for `onSubmit` callbacks returning values to `useSubmit` or `useForm` * @param errors - An array of errors with the user's input. These can either include both a `fieldPath` and a `message`, in which case they will be passed down to a matching field, or just a `message`. * @return Returns a `SubmitResult` representing your failed form submission. */ export declare function submitFail(errors?: FormError[]): SubmitResult;