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( cmd: K, payload: Req, opts?: Omit>, 'queryKey' | 'queryFn'>, ) { return useQuery>({ queryKey: [cmd, payload], queryFn: () => rpc(cmd, payload), ...opts, }); }