2023-01-15 19:40:47 +00:00
|
|
|
import { useSyncExternalStore } from "react";
|
2023-02-11 20:05:46 +00:00
|
|
|
import { System, StateSnapshot } from "@snort/nostr";
|
2023-01-15 19:40:47 +00:00
|
|
|
|
2023-02-07 19:47:57 +00:00
|
|
|
const noop = () => {
|
|
|
|
return () => undefined;
|
2023-02-07 20:04:50 +00:00
|
|
|
};
|
2023-01-16 17:48:25 +00:00
|
|
|
const noopState = (): StateSnapshot | undefined => {
|
2023-02-07 20:04:50 +00:00
|
|
|
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);
|
2023-02-07 20:04:50 +00:00
|
|
|
return useSyncExternalStore<StateSnapshot | undefined>(
|
|
|
|
c?.StatusHook.bind(c) ?? noop,
|
|
|
|
c?.GetState.bind(c) ?? noopState
|
|
|
|
);
|
|
|
|
}
|