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

Method trackResult

packages/query-core/src/queryObserver.ts:342–353  ·  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

340 * @returns A proxy of `result` that tracks property reads.
341 */
342 trackResult(
343 result: QueryObserverResult<TData, TError>,
344 onPropTracked?: (key: keyof QueryObserverResult) => void,
345 ): QueryObserverResult<TData, TError> {
346 return new Proxy(result, {
347 get: (target, key) => {
348 this.trackProp(key as keyof QueryObserverResult)
349 onPropTracked?.(key as keyof QueryObserverResult)
350 return Reflect.get(target, key)
351 },
352 })
353 }
354
355 /**
356 * 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