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

19 lines
482 B
TypeScript
Raw Normal View History

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