Files
yaak/apps/yaak-proxy/hooks/useRpcEvent.ts
2026-03-12 08:31:05 -07:00

16 lines
433 B
TypeScript

import type { RpcEventSchema } from '@yaakapp-internal/proxy-lib';
import { useEffect } from 'react';
import { listen } from '../lib/rpc';
/**
* Subscribe to an RPC event. Cleans up automatically on unmount.
*/
export function useRpcEvent<K extends keyof RpcEventSchema>(
event: K & string,
callback: (payload: RpcEventSchema[K]) => void,
) {
useEffect(() => {
return listen(event, callback);
}, [event, callback]);
}