MCPcopy Create free account
hub / github.com/TanStack/query / subscribe

Method subscribe

packages/query-core/src/subscribable.ts:27–36  ·  view source on GitHub ↗

* Registers a listener to be called on every update this object notifies about. Returns a function * that removes the listener again — call it to stop listening. The base class never drops a listener * on its own, though some subclasses clear all of theirs in `destroy()`. * @param listener

(listener: TListener)

Source from the content-addressed store, hash-verified

25 * ```
26 */
27 subscribe(listener: TListener): () => void {
28 this.listeners.add(listener)
29
30 this.onSubscribe()
31
32 return () => {
33 this.listeners.delete(listener)
34 this.onUnsubscribe()
35 }
36 }
37
38 /**
39 * Returns `true` while at least one listener is registered, `false` once they have all unsubscribed.

Callers 15

useBaseQueryFunction · 0.45
useMutationFunction · 0.45
useMutationStateFunction · 0.45
useQueriesFunction · 0.45
useIsFetchingFunction · 0.45
setupDevtoolsFunction · 0.45
DevtoolsFunction · 0.45
addObserverFunction · 0.45

Calls 3

onSubscribeMethod · 0.95
onUnsubscribeMethod · 0.95
addMethod · 0.45

Tested by 2

addObserverFunction · 0.36
subscribeFunction · 0.36