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

Method updateResult

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

Source from the content-addressed store, hash-verified

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

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