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

( action: (...params: [...P, { db: DbInterface; store: Store }]) => Promise, ): (...args: P) => Promise { 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], ); }