Files
abode/src/react/hooks/useAction.ts
T
codingetandCodex 31d4636dde
CI / install-and-build (pull_request) Successful in 1m29s
CI / format (pull_request) Successful in 51s
CI / typecheck-source (pull_request) Successful in 41s
CI / typecheck-tests (pull_request) Successful in 39s
CI / test (pull_request) Successful in 51s
CI / lint (pull_request) Successful in 21s
ci: add pull request quality gates
Co-Authored-By: gpt-5.6-terra <noreply@openai.com>
2026-07-22 21:50:29 +00:00

21 lines
648 B
TypeScript

import { use, useCallback } from "react";
import { DbContext } from "../contexts/Db.js";
import type { DbInterface } from "../../db/types/DbInterface.js";
import type { Store } from "../store/store.js";
import { useStore } from "../store/react.js";
export function useAction<P extends any[], R>(
action: (...params: [...P, { db: DbInterface; store: Store }]) => Promise<R>,
): (...args: P) => Promise<R> {
const db = use(DbContext);
const store = useStore();
return useCallback(
async (...params: P) => {
if (!db) throw new Error("DB not present");
return action(...params, { db, store });
},
[action, db],
);
}