import type { ChangeEvent, RefObject } from 'react'; import type { ReactSetState } from "../use-safe-state/index.cjs"; export interface UseFormOptions { /** * Initial value of the form * * @defaultValue {} */ initialValue?: FormState; /** * Callback to be called when the form value changes * * @defaultValue undefined */ onChange?(form: FormState): void; /** * Callback to be called when the form is submitted * * @defaultValue undefined */ onSubmit?(form: FormState): void; /** * Callback to be called when the form is reset * * @defaultValue undefined */ onReset?(): void; /** * When use `nativeProps`, whether to prevent default when the form is submitted * * @defaultValue true */ preventDefaultWhenSubmit?: boolean; /** * Whether to emit change event when the form is reset * * @defaultValue false * * @deprecated will be removed in the next major version */ triggerOnChangeWhenReset?: boolean; } export type UseFormReturnsNativeProps = { /** * Ref of the form element */ ref: RefObject; /** * Callback to be called when the form value changes */ onChange(e: ChangeEvent): void; /** * Callback to be called when the form is submitted */ onSubmit(e: ChangeEvent): void; /** * Callback to be called when the form is reset */ onReset(e: ChangeEvent): void; }; export interface UseFormReturns { /** * Whether the form is submitting */ submitting: boolean; /** * Set the new value of the whole form */ setValue: ReactSetState; /** * Set a field value of the form */ setFieldValue(name: Name, value: FormState[Name]): void; /** * Reset the form to its initial value */ reset(): void; /** * Submit the form */ submit(): void; /** * Current value of the form */ value: FormState; /** * Initial value of the form */ initialValue: FormState; /** * handle form value changes */ handleChange(form: FormState): void; /** * handle form submit */ handleSubmit(form: FormState): void; /** * handle form reset */ handleReset(): void; /** * Check and report the native form validity, only valid for native form */ reportValidity(): boolean; /** * Check the native form validity, only valid for native form */ checkValidity(): boolean; /** * Native form related props */ nativeProps: UseFormReturnsNativeProps; } /** * A React Hook to manage form state with ease * * @param {UseFormOptions} options Options to customize the form behavior * * @since 1.7.0 */ export declare function useForm(options?: UseFormOptions): UseFormReturns;