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

Method trackResult

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

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