Function
useSubscription
({
// (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(). |
| 18 | export 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 | } |