MCPcopy Create free account
hub / github.com/dailydotdev/apps / useSubscription

Function useSubscription

packages/shared/src/hooks/useSubscription.ts:14–45  ·  view source on GitHub ↗
(
  request: () => { query: string; variables?: Record<string, unknown> },
  { next, error }: SubscriptionCallbacks<T>,
  deps?: DependencyList,
)

Source from the content-addressed store, hash-verified

12}
13
14export default function useSubscription<T>(
15 request: () => { query: string; variables?: Record<string, unknown> },
16 { next, error }: SubscriptionCallbacks<T>,
17 deps?: DependencyList,
18): void {
19 const { subscriptionClient, connected } = useContext(SubscriptionContext);
20 const nextRef = useRef(next);
21 const errorRef = useRef(error);
22
23 useEffect(() => {
24 nextRef.current = next;
25 }, [next]);
26
27 useEffect(() => {
28 errorRef.current = error;
29 }, [error]);
30
31 useEffect(() => {
32 if (connected) {
33 return subscriptionClient.subscribe<T>(request(), {
34 next: ({ data }: Payload<T>) => {
35 nextRef.current?.(data);
36 },
37 error: (subscribeError) => errorRef.current?.(subscribeError),
38 complete: () => {},
39 });
40 }
41 return undefined;
42 // @NOTE see https://dailydotdev.atlassian.net/l/cp/dK9h1zoM
43 // eslint-disable-next-line react-hooks/exhaustive-deps
44 }, [connected, ...(deps ?? [])]);
45}

Callers 5

usePostContentFunction · 0.85
useQuestUpdatesFunction · 0.85
useFeedFunction · 0.85
useInAppNotificationFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected