MCPcopy
hub / github.com/facebook/react / useSubscription

Function useSubscription

packages/use-subscription/src/useSubscription.js:18–30  ·  view source on GitHub ↗
({
  // (Synchronously) returns the current value of our subscription.
  getCurrentValue,

  // This function is passed an event handler to attach to the subscription.
  // It should return an unsubscribe function that removes the handler.
  subscribe,
}: {
  getCurrentValue: () => Value,
  subscribe: (callback: Function) => () => void,
})

Source from the content-addressed store, hash-verified

16// either by wrapping the entire params object with useMemo()
17// or by wrapping the individual callbacks with useCallback().
18export function useSubscription<Value>({
19 // (Synchronously) returns the current value of our subscription.
20 getCurrentValue,
21
22 // This function is passed an event handler to attach to the subscription.
23 // It should return an unsubscribe function that removes the handler.
24 subscribe,
25}: {
26 getCurrentValue: () => Value,
27 subscribe: (callback: Function) => () => void,
28}): Value {
29 return useSyncExternalStore(subscribe, getCurrentValue);
30}

Callers 2

SubscriptionFunction · 0.50
SubscriberFunction · 0.50

Calls 1

useSyncExternalStoreFunction · 0.50

Tested by 2

SubscriptionFunction · 0.40
SubscriberFunction · 0.40