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
|
|
|
|
2023-02-07 20:04:50 +00:00
|
|
|
const noop = (f: CustomHook) => {
|
|
|
|
return () => {};
|
|
|
|
};
|
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 20:04:50 +00:00
|
|
|
let c = System.Sockets.get(addr);
|
|
|
|
return useSyncExternalStore<StateSnapshot | undefined>(
|
|
|
|
c?.StatusHook.bind(c) ?? noop,
|
|
|
|
c?.GetState.bind(c) ?? noopState
|
|
|
|
);
|
|
|
|
}
|