Skip to content

ActionDefinition

ActionDefinition<TInput, TResult, TUser> = object

Defined in: packages/actions/src/types.ts:280

A single action definition returned by createAction().

Provides four facets: a React Router action handler, a loader wrapper that injects permission status, a client descriptor for useActions, and a buildOperation method for advanced composition.

const deletePost = createAction<{ postId: string }, Response>(
(db, input, ctx) =>
compose(
[db.delete(posts).where(eq(posts.id, input.postId))],
async (runDelete) => { await runDelete({}); return redirect("/"); },
),
);
// Use as a route action
export const action = deletePost.action;
// Wrap a loader to inject permissions
export const loader = deletePost.loader(myLoader);

TInput

The expected input shape for this action.

TResult

The return type of the action handler.

TUser

The shape of the authenticated user object.

action: (args) => Promise<TResult>

Defined in: packages/actions/src/types.ts:282

React Router action handler. Parses input, resolves context, and runs the operation.

RequestArgs

Promise<TResult>


buildOperation: (db, input, ctx) => Operation<TResult>

Defined in: packages/actions/src/types.ts:320

Builds the raw Operation for this action, useful for cross-action composition.

Db

TInput

ActionContext<TUser>

Operation<TResult>


client: ClientDescriptor

Defined in: packages/actions/src/types.ts:318

Opaque descriptor for the useActions client hook.


dispatch: (args) => Promise<TResult>

Defined in: packages/actions/src/types.ts:306

Dispatches the action using an already-resolved ActionContext, bypassing getContext() entirely.

Use this when a parent action handler needs to invoke a sub-action. Because the parent’s ctx is reused directly, cookies, user session, and grants are inherited without constructing a new Request — which eliminates the cookie-forwarding bug described in issue #185.

DispatchArgs<TInput, TUser>

The DispatchArgs containing the parent’s ctx and the typed input for this action.

Promise<TResult>

The action’s result, same as calling .action().

const parent = createAction((db, input, ctx) => ({
permissions: [],
async run() {
return child.dispatch({ ctx, input: { title: "Hello" } });
},
}));

loader: <TLoaderData>(loaderFn) => (args) => Promise<TLoaderData & object>

Defined in: packages/actions/src/types.ts:314

Wraps a loader function to inject ActionPermissionsMap into its return value.

The wrapper resolves the action context, builds the operation to extract permission descriptors, checks them against the user’s grants, and merges the result as _actionPermissions.

TLoaderData extends Record<string, Serializable>

(args) => Promise<TLoaderData>

(args): Promise<TLoaderData & object>

RequestArgs

Promise<TLoaderData & object>