import type { TrackedActionState } from "../types.js"; /** * Extract action ID from a server action function or string. * * Actions passed as props from server components lose their metadata * during RSC serialization - use a string action name instead. */ export declare function getActionId(action: ServerActionFunction | string): string; /** * Server action function type * Server actions have a $$id property added by the RSC compiler */ export type ServerActionFunction = ((...args: any[]) => Promise) & { $$id?: string; }; /** * Hook to track the lifecycle of a specific server action * * Unlike useNavigation which tracks global navigation state, useAction * tracks the state of individual server action invocations. * * Uses the event controller for reactive state management. * State is derived from the inflight actions tracked by the controller. * * Features: * - Tracks action lifecycle: idle → loading → streaming → idle * - Captures result/error locally (React handles cleanup) * - If multiple actions fire, tracks only the last one * - Supports selector pattern like useNavigation * * Matching behavior: * - **Function reference**: Uses full $$id for exact matching. This is precise * and distinguishes between actions with the same name in different files. * - **String**: Matches by suffix (action name after #). This is convenient * but may be ambiguous if multiple files export the same action name. * * @param action - Either a server action function or a string action name. * - **Function**: Must be directly imported in the client component. * Actions passed as props from server components will throw an error. * - **String**: The exported function name from your "use server" file. * Matches any action ending with "#actionName" (suffix match). * * @example * ```tsx * // Option 1: Direct import (precise matching) * import { addToCart } from './actions'; * const actionState = useAction(addToCart); * * // Option 2: String-based (suffix matching) * // Matches "hash#addToCart" or "src/actions.ts#addToCart" * const actionState = useAction('addToCart'); * * // With selector for specific values * const isLoading = useAction(addToCart, state => state.state === 'loading'); * const error = useAction(addToCart, state => state.error); * ``` * * @note Actions passed as props from server components lose their metadata * during RSC serialization. Use a string action name or import directly. */ export declare function useAction(action: ServerActionFunction | string): TrackedActionState; export declare function useAction(action: ServerActionFunction | string, selector: (state: TrackedActionState) => T): T; export type { TrackedActionState }; //# sourceMappingURL=use-action.d.ts.map