mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-10 03:03:37 +02:00
Refactor proxy codebase
This commit is contained in:
20
apps/yaak-proxy/hooks/useRpcQuery.ts
Normal file
20
apps/yaak-proxy/hooks/useRpcQuery.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { type UseQueryOptions, useQuery } from '@tanstack/react-query';
|
||||
import type { RpcSchema } from '@yaakapp-internal/proxy-lib';
|
||||
import type { Req, Res } from '../lib/rpc';
|
||||
import { rpc } from '../lib/rpc';
|
||||
|
||||
/**
|
||||
* React Query wrapper for RPC commands.
|
||||
* Automatically caches by [cmd, payload] and supports all useQuery options.
|
||||
*/
|
||||
export function useRpcQuery<K extends keyof RpcSchema>(
|
||||
cmd: K,
|
||||
payload: Req<K>,
|
||||
opts?: Omit<UseQueryOptions<Res<K>>, 'queryKey' | 'queryFn'>,
|
||||
) {
|
||||
return useQuery<Res<K>>({
|
||||
queryKey: [cmd, payload],
|
||||
queryFn: () => rpc(cmd, payload),
|
||||
...opts,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user