snort/src/feed/RelayState.ts

13 lines
506 B
TypeScript
Raw Normal View History

2023-01-15 19:40:47 +00:00
import { useSyncExternalStore } from "react";
import { System } from "../nostr/System";
2023-01-16 17:48:25 +00:00
import { CustomHook, StateSnapshot } from "../nostr/Connection";
2023-01-15 19:40:47 +00:00
const noop = (f: CustomHook) => { return () => { }; };
2023-01-16 17:48:25 +00:00
const noopState = (): StateSnapshot | undefined => {
return undefined;
};
2023-01-15 19:40:47 +00:00
export default function useRelayState(addr: string) {
let c = System.Sockets.get(addr);
2023-01-16 17:48:25 +00:00
return useSyncExternalStore<StateSnapshot | undefined>(c?.StatusHook.bind(c) ?? noop, c?.GetState.bind(c) ?? noopState);
2023-01-15 19:40:47 +00:00
}