mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-02 19:17:10 +00:00
Renames inspect-ui/ to replay-ui/, internal/inspect/ to internal/replay/, the CLI subcommand from `sanderling inspect` to `sanderling replay`, and updates all references in docs, Makefile, README, and Go comments.
19 lines
492 B
TypeScript
19 lines
492 B
TypeScript
import { useEffect } from "react";
|
|
|
|
export function useSse(eventName: string, onEvent: () => void) {
|
|
useEffect(() => {
|
|
if (typeof EventSource === "undefined") {
|
|
return;
|
|
}
|
|
const source = new EventSource("/api/events");
|
|
const messageHandler = () => {
|
|
onEvent();
|
|
};
|
|
source.addEventListener(eventName, messageHandler);
|
|
return () => {
|
|
source.removeEventListener(eventName, messageHandler);
|
|
source.close();
|
|
};
|
|
}, [eventName, onEvent]);
|
|
}
|