mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-23 01:08:28 +02:00
Refactor proxy codebase
This commit is contained in:
18
apps/yaak-proxy/hooks/useRpcMutation.ts
Normal file
18
apps/yaak-proxy/hooks/useRpcMutation.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { type UseMutationOptions, useMutation } from '@tanstack/react-query';
|
||||
import type { RpcSchema } from '@yaakapp-internal/proxy-lib';
|
||||
import { minPromiseMillis } from '@yaakapp-internal/ui';
|
||||
import type { Req, Res } from '../lib/rpc';
|
||||
import { rpc } from '../lib/rpc';
|
||||
|
||||
/**
|
||||
* React Query mutation wrapper for RPC commands.
|
||||
*/
|
||||
export function useRpcMutation<K extends keyof RpcSchema>(
|
||||
cmd: K,
|
||||
opts?: Omit<UseMutationOptions<Res<K>, Error, Req<K>>, 'mutationFn'>,
|
||||
) {
|
||||
return useMutation<Res<K>, Error, Req<K>>({
|
||||
mutationFn: (payload) => minPromiseMillis(rpc(cmd, payload)),
|
||||
...opts,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user