import { A as ActionResult, T as ToastAdapter, S as ServerAction } from '../index-CpykiB6f.js'; import * as react from 'react'; import { ReactNode } from 'react'; interface UseServerActionOptions { onSuccess?: (data: TOutput) => void | Promise; onError?: (error: ActionResult) => void | Promise; /** Message of the success toast when `showSuccessToast` is `true`. */ successMessage?: string | ((data: TOutput) => string); /** Message of the error toast; defaults to the server error or fetch error message. */ errorMessage?: string | ((error: ActionResult) => string); /** `true` (uses `successMessage`, or "Success!"), a message, or a function returning it. */ showSuccessToast?: boolean | string | ((data: TOutput) => string); /** Default `true`. */ showErrorToast?: boolean; /** Overrides the adapter of `` for this hook. */ toast?: ToastAdapter; /** Follow `shouldRedirect`/`redirectTo` on authentication errors. Default `true`. */ redirectOnAuthError?: boolean; /** 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; } interface UseServerActionReturn { execute: TInput extends void ? () => Promise> : (input: TInput) => Promise>; result: ActionResult | undefined; isExecuting: boolean; isRedirecting: boolean; hasSucceeded: boolean; hasErrored: boolean; reset: () => void; } declare function useServerAction(action: ServerAction, options?: UseServerActionOptions): UseServerActionReturn; declare function useServerAction(action: ServerAction, options?: UseServerActionOptions): UseServerActionReturn; interface UseOptimisticActionOptions extends UseServerActionOptions { /** * Compute the optimistic state from the current one and the input. It must * be pure: React may call it again while the action is pending. */ updateFn: TInput extends void ? (current: TOptimistic) => TOptimistic : (current: TOptimistic, input: TInput) => TOptimistic; } interface UseOptimisticActionReturn { /** * The optimistic state while the action is pending, otherwise the state * passed to the hook. Refresh that state (for example with * `revalidatePath` in the action) so it reflects the result once done. */ optimisticState: TOptimistic; /** * Execute the action with optimistic update */ execute: TInput extends void ? () => Promise> : (input: TInput) => Promise>; isExecuting: boolean; isRedirecting: boolean; hasSucceeded: boolean; hasErrored: boolean; result: ActionResult | undefined; reset: () => void; } /** * Hook for server actions with optimistic updates. The optimistic update and * the server call run in one transition, as React's `useOptimistic` * requires, so the optimistic state stays visible until the action settles. * * @example * ```typescript * const { optimisticState, execute } = useOptimisticAction( * todos, * toggleTodoAction, * { updateFn: (todos, { id }) => todos.map((t) => (t.id === id ? { ...t, done: !t.done } : t)) }, * ); * ``` */ declare function useOptimisticAction(initialState: TOptimistic, action: ServerAction, options: UseOptimisticActionOptions): UseOptimisticActionReturn; declare function useOptimisticAction(initialState: TOptimistic, action: ServerAction, options: UseOptimisticActionOptions): UseOptimisticActionReturn; interface ActionForgeConfig { /** Shows the success and error toasts requested by the hooks. */ toast?: ToastAdapter; } interface ActionForgeProviderProps extends ActionForgeConfig { children: ReactNode; } /** * Configures every next-action-forge hook below it. Render it inside a * Client Component, because `toast` is a function: * * ```tsx * "use client"; * import { toast } from "sonner"; * import { ActionForgeProvider } from "next-action-forge/hooks"; * * export function Providers({ children }: { children: React.ReactNode }) { * return {children}; * } * ``` */ declare function ActionForgeProvider({ toast, children }: ActionForgeProviderProps): react.JSX.Element; export { type ActionForgeConfig, ActionForgeProvider, type ActionForgeProviderProps, ActionResult, ToastAdapter, type UseOptimisticActionOptions, type UseOptimisticActionReturn, type UseServerActionOptions, type UseServerActionReturn, useOptimisticAction, useServerAction };