snort/packages/app/src/Feed/RelayState.ts

19 lines
482 B
TypeScript

import { useSyncExternalStore } from "react";
import { StateSnapshot } from "@snort/nostr";
import { System } from "System";
const noop = () => {
return () => undefined;
};
const noopState = (): StateSnapshot | undefined => {
return undefined;
};
export default function useRelayState(addr: string) {
const c = System.Sockets.get(addr);
return useSyncExternalStore<StateSnapshot | undefined>(
c?.StatusHook.bind(c) ?? noop,
c?.GetState.bind(c) ?? noopState
);
}