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

Method trackResult

packages/query-core/src/queryObserver.ts:331–342  ·  view source on GitHub ↗

* Wraps a `QueryObserverResult` in a `Proxy` that records which properties are read, via * QueryObserver#trackProp (and an optional `onPropTracked` callback). Used by framework * adapters when `notifyOnChangeProps` is not set, to implement its default "only re-render on * properties

(
    result: QueryObserverResult<TData, TError>,
    onPropTracked?: (key: keyof QueryObserverResult) => void,
  )

Source from the content-addressed store, hash-verified

329 * properties you actually read" behavior.
330 */
331 trackResult(
332 result: QueryObserverResult<TData, TError>,
333 onPropTracked?: (key: keyof QueryObserverResult) => void,
334 ): QueryObserverResult<TData, TError> {
335 return new Proxy(result, {
336 get: (target, key) => {
337 this.trackProp(key as keyof QueryObserverResult)
338 onPropTracked?.(key as keyof QueryObserverResult)
339 return Reflect.get(target, key)
340 },
341 })
342 }
343
344 /**
345 * Records that the given `QueryObserverResult` property was read, so a subsequent update only

Callers 7

useBaseQueryFunction · 0.45
useBaseQueryFunction · 0.45
createResultFunction · 0.45
#trackResultMethod · 0.45

Calls 2

trackPropMethod · 0.95
getMethod · 0.80

Tested by

no test coverage detected