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

Method updateResult

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

Source from the content-addressed store, hash-verified

643 }
644
645 updateResult(): void {
646 const prevResult = this.#currentResult as
647 | QueryObserverResult<TData, TError>
648 | undefined
649
650 const nextResult = this.createResult(this.#currentQuery, this.options)
651
652 this.#currentResultState = this.#currentQuery.state
653 this.#currentResultOptions = this.options
654
655 if (this.#currentResultState.data !== undefined) {
656 this.#lastQueryWithDefinedData = this.#currentQuery
657 }
658
659 // Only notify and update result if something has changed
660 if (shallowEqualObjects(nextResult, prevResult)) {
661 return
662 }
663
664 this.#currentResult = nextResult
665
666 const shouldNotifyListeners = (): boolean => {
667 if (!prevResult) {
668 return true
669 }
670
671 const { notifyOnChangeProps } = this.options
672 const notifyOnChangePropsValue =
673 typeof notifyOnChangeProps === 'function'
674 ? notifyOnChangeProps()
675 : notifyOnChangeProps
676
677 if (
678 notifyOnChangePropsValue === 'all' ||
679 (!notifyOnChangePropsValue && !this.#trackedProps.size)
680 ) {
681 return true
682 }
683
684 const includedProps = new Set(
685 notifyOnChangePropsValue ?? this.#trackedProps,
686 )
687
688 if (this.options.throwOnError) {
689 includedProps.add('error')
690 }
691
692 return Object.keys(this.#currentResult).some((key) => {
693 const typedKey = key as keyof QueryObserverResult
694 const changed = this.#currentResult[typedKey] !== prevResult[typedKey]
695
696 return changed && includedProps.has(typedKey)
697 })
698 }
699
700 this.#notify({ listeners: shouldNotifyListeners() })
701 }
702

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 3

createResultMethod · 0.95
#notifyMethod · 0.95
shallowEqualObjectsFunction · 0.90

Tested by

no test coverage detected