mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-08-26 05:14:11 +02:00
Add a typed platform package to decouple the frontend from Tauri (#539)
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
0068be9ffc
commit
2383f06e71
@@ -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