snapshot of https://github.com/mountain-loop/yaak.git (main, 2026-09-23; blobs > 131072B omitted)
This commit is contained in:
12
apps/yaak-client/hooks/usePlatformEvent.ts
Normal file
12
apps/yaak-client/hooks/usePlatformEvent.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { platform } from "@yaakapp-internal/platform";
|
||||
import { useEffect, useRef } from "react";
|
||||
|
||||
/** Subscribe to a backend event for the lifetime of the component. */
|
||||
export function usePlatformEvent<T>(event: string, fn: (payload: T) => void) {
|
||||
const handlerRef = useRef(fn);
|
||||
useEffect(() => {
|
||||
handlerRef.current = fn;
|
||||
}, [fn]);
|
||||
|
||||
useEffect(() => platform.listen<T>(event, (payload) => handlerRef.current(payload)), [event]);
|
||||
}
|
||||
Reference in New Issue
Block a user