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

Method updateResult

packages/query-core/src/queryObserver.ts:623–694  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

621 }
622
623 updateResult(): void {
624 const prevResult = this.#currentResult as
625 | QueryObserverResult<TData, TError>
626 | undefined
627
628 const nextResult = this.createResult(this.#currentQuery, this.options)
629
630 this.#currentResultState = this.#currentQuery.state
631 this.#currentResultOptions = this.options
632
633 if (this.#currentResultState.data !== undefined) {
634 this.#lastQueryWithDefinedData = this.#currentQuery
635 }
636
637 // Only notify and update result if something has changed
638 if (shallowEqualObjects(nextResult, prevResult)) {
639 return
640 }
641
642 this.#currentResult = nextResult
643
644 const shouldNotifyListeners = (): boolean => {
645 if (!prevResult) {
646 return true
647 }
648
649 const { notifyOnChangeProps } = this.options
650 const notifyOnChangePropsValue =
651 typeof notifyOnChangeProps === 'function'
652 ? notifyOnChangeProps()
653 : notifyOnChangeProps
654
655 if (
656 notifyOnChangePropsValue === 'all' ||
657 (!notifyOnChangePropsValue && !this.#trackedProps.size)
658 ) {
659 return true
660 }
661
662 const includedProps = new Set(
663 notifyOnChangePropsValue ?? this.#trackedProps,
664 )
665
666 if (this.options.throwOnError) {
667 includedProps.add('error')
668 }
669
670 return Object.keys(this.#currentResult).some((key) => {
671 const typedKey = key as keyof QueryObserverResult
672 const changed = this.#currentResult[typedKey] !== prevResult[typedKey]
673
674 return changed && includedProps.has(typedKey)
675 })
676 }
677
678 const notifyListeners = shouldNotifyListeners()
679
680 notifyManager.batch(() => {

Callers 13

onSubscribeMethod · 0.95
setOptionsMethod · 0.95
fetchMethod · 0.95
#updateStaleTimeoutMethod · 0.95
onQueryUpdateMethod · 0.95
onConnectedMethod · 0.80
onQueryClientChangedMethod · 0.80
onConnectedMethod · 0.80
onQueryClientChangedMethod · 0.80
useBaseQueryFunction · 0.80
useBaseQueryFunction · 0.80
createBaseQueryFunction · 0.80

Calls 5

createResultMethod · 0.95
shallowEqualObjectsFunction · 0.90
getQueryCacheMethod · 0.80
listenerFunction · 0.50
notifyMethod · 0.45

Tested by

no test coverage detected