2023-01-15 19:40:47 +00:00
|
|
|
import { useSyncExternalStore } from "react";
|
2023-01-20 11:11:50 +00:00
|
|
|
import { System } from "Nostr/System";
|
|
|
|
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
|
|
|
}
|