mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-05-14 03:40:25 +02:00
Split codebase (#455)
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