import { BaseSyntheticEvent } from 'react'; import { FieldValues, DefaultValues, UseFormProps, UseFormReturn } from 'react-hook-form'; import { $ZodType } from 'zod/v4/core'; import { a as ServerActionResponse, b as ServerActionError, T as ToastAdapter, A as ActionResult } from '../../index-CpykiB6f.js'; /** * A regular server action receiving the form values. Its input is not tied * to the form's field types, so an action chosen at runtime * (`isEdit ? updateUser : createUser`) works; the action's schema validates * on the server. Actions created with `.formAction()` expect FormData and are * rejected by their `~formAction` marker. */ type FormSubmitAction = ((input: never) => Promise>) & { readonly "~formAction"?: never; }; /** What the action returns on success; distributes over an action chosen at runtime. */ type FormActionOutput = TAction extends (...args: any[]) => Promise> ? TOutput : never; interface UseFormActionOptions = FormSubmitAction> { /** * A server action created with `.action()`: it receives the form values * as an object, so Dates, numbers, booleans and Files keep their types. * A `.formAction()` expects FormData and is rejected. */ action: TAction; /** * Schema for client-side validation (Zod or Zod Mini). The action still * validates on the server; the form sends the raw values, not the parsed ones. */ schema?: $ZodType; /** * Initial values. They also type the form fields, which keeps fields such * as `z.coerce.number()` (whose schema input is `unknown`) typed as numbers. */ defaultValues?: DefaultValues; mode?: UseFormProps["mode"]; /** Any other react-hook-form option. */ formOptions?: Omit, "resolver" | "defaultValues" | "mode">; /** Map the form values to the action input when they differ. */ transformData?: (values: TFieldValues) => unknown; onSuccess?: (data: FormActionOutput) => void | Promise; onError?: (error: ServerActionError) => void | Promise; /** Reset the form after a success. Default `false`. */ resetOnSuccess?: boolean; /** `true` ("Success!"), a message, or a function returning it. Default `false`. */ showSuccessToast?: boolean | string | ((data: FormActionOutput) => string); /** * Toast for errors that do not belong to a field: `true` (the error * message), a message, or a function returning it. Field errors are shown * on their inputs instead. Default `true`. */ showErrorToast?: boolean | string | ((error: ServerActionError) => string); /** Overrides the adapter of `` for this hook. */ toast?: ToastAdapter; /** Ignore the redirect returned by the action. Default `false`. */ preventRedirect?: boolean; /** Delay in ms before following a redirect without its own `delay`. Default `0`. */ redirectDelay?: number; /** Follow `shouldRedirect`/`redirectTo` on authentication errors. Default `true`. */ redirectOnAuthError?: boolean; } interface UseFormActionReturn { /** The react-hook-form instance. */ form: UseFormReturn; /** Submit handler for `
`: validates, then calls the action. */ onSubmit: (event?: BaseSyntheticEvent) => Promise; /** True from the submit until the action settled. */ isSubmitting: boolean; /** True while a redirect returned by the action is in progress. */ isRedirecting: boolean; /** The last result, as returned by `useServerAction`. */ result: ActionResult | undefined; /** The last response of the action, or `undefined` before the first submit. */ actionState: ServerActionResponse | undefined; /** Reset the form and the last result. */ reset: () => void; /** Call the action with already validated values, bypassing the form's validation. */ handleSubmit: (values: TFieldValues) => Promise; } /** * react-hook-form bound to a server action: client-side validation with an * optional schema, the values sent as an object to a `.action()`, server * field errors mapped to their inputs (dotted paths), form-level errors on * `errors.root` and in a toast, and the redirects of `useServerAction`. */ declare function useFormAction = FormSubmitAction>(options: UseFormActionOptions): UseFormActionReturn>; export { type FormActionOutput, type FormSubmitAction, type UseFormActionOptions, type UseFormActionReturn, useFormAction };