next-safe-action
Version:
Type safe and validated Server Actions in your Next.js project.
75 lines (72 loc) • 2.23 kB
text/typescript
import { Schema, InferIn } from "./adapters/types.mjs";
import {
H as HookSafeActionFn,
a as HookBaseUtils,
b as HookCallbacks,
U as UseActionHookReturn,
c as UseOptimisticActionHookReturn,
} from "./hooks.types-CuSFdF4W.mjs";
export {
e as HookActionStatus,
d as HookSafeStateActionFn,
f as HookShorthandStatus,
I as InferUseActionHookReturn,
h as InferUseOptimisticActionHookReturn,
i as InferUseStateActionHookReturn,
g as UseStateActionHookReturn,
} from "./hooks.types-CuSFdF4W.mjs";
import "@sinclair/typebox";
import "valibot";
import "yup";
import "zod";
import "./index.types-Cct3QIs2.mjs";
/**
* Use the action from a Client Component via hook.
* @param safeActionFn The action function
* @param utils Optional base utils and callbacks
*
* {@link https://next-safe-action.dev/docs/execute-actions/hooks/useaction See docs for more information}
*/
declare const useAction: <
ServerError,
S extends Schema | undefined,
const BAS extends readonly Schema[],
CVE,
CBAVE,
Data,
>(
safeActionFn: HookSafeActionFn<ServerError, S, BAS, CVE, CBAVE, Data>,
utils?: HookBaseUtils<S> & HookCallbacks<ServerError, S, BAS, CVE, CBAVE, Data>
) => UseActionHookReturn<ServerError, S, BAS, CVE, CBAVE, Data>;
/**
* Use the action from a Client Component via hook, with optimistic data update.
* @param safeActionFn The action function
* @param utils Required `currentData` and `updateFn` and optional base utils and callbacks
*
* {@link https://next-safe-action.dev/docs/execute-actions/hooks/useoptimisticaction See docs for more information}
*/
declare const useOptimisticAction: <
ServerError,
S extends Schema | undefined,
const BAS extends readonly Schema[],
CVE,
CBAVE,
Data,
State,
>(
safeActionFn: HookSafeActionFn<ServerError, S, BAS, CVE, CBAVE, Data>,
utils: {
currentState: State;
updateFn: (state: State, input: S extends Schema ? InferIn<S> : undefined) => State;
} & HookBaseUtils<S> &
HookCallbacks<ServerError, S, BAS, CVE, CBAVE, Data>
) => UseOptimisticActionHookReturn<ServerError, S, BAS, CVE, CBAVE, Data, State>;
export {
HookBaseUtils,
HookCallbacks,
HookSafeActionFn,
UseActionHookReturn,
UseOptimisticActionHookReturn,
useAction,
useOptimisticAction,
};