mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-27 11:17:01 +02:00
Refactor proxy codebase
This commit is contained in:
15
apps/yaak-proxy/hooks/useRpcEvent.ts
Normal file
15
apps/yaak-proxy/hooks/useRpcEvent.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
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]);
|
||||
}
|
||||
Reference in New Issue
Block a user