mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-22 01:19:39 +01:00
16 lines
433 B
TypeScript
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]);
|
|
}
|