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

Method setOptions

packages/query-core/src/mutationObserver.ts:100–129  ·  view source on GitHub ↗

* Updates the observer's options. * * If the new `mutationKey` differs from the previous one (and both were * defined), the observer is reset, detaching it from the mutation it was * observing. Otherwise, if the currently observed mutation is still * `pending`, its options are updated

(
    options: MutationObserverOptions<
      TData,
      TError,
      TVariables,
      TOnMutateResult
    >,
  )

Source from the content-addressed store, hash-verified

98 * ```
99 */
100 setOptions(
101 options: MutationObserverOptions<
102 TData,
103 TError,
104 TVariables,
105 TOnMutateResult
106 >,
107 ) {
108 const prevOptions = this.options as
109 | MutationObserverOptions<TData, TError, TVariables, TOnMutateResult>
110 | undefined
111 this.options = this.#client.defaultMutationOptions(options)
112 if (!shallowEqualObjects(this.options, prevOptions)) {
113 this.#client.getMutationCache().notify({
114 type: 'observerOptionsUpdated',
115 mutation: this.#currentMutation,
116 observer: this,
117 })
118 }
119
120 if (
121 prevOptions?.mutationKey &&
122 this.options.mutationKey &&
123 hashKey(prevOptions.mutationKey) !== hashKey(this.options.mutationKey)
124 ) {
125 this.reset()
126 } else if (this.#currentMutation?.state.status === 'pending') {
127 this.#currentMutation.setOptions(this.options)
128 }
129 }
130
131 protected override onSubscribe(): void {
132 if (this.listeners.size === 1 && this.#currentMutation) {

Callers 3

useMutationFunction · 0.95
useMutationFunction · 0.95
constructorMethod · 0.95

Calls 6

resetMethod · 0.95
shallowEqualObjectsFunction · 0.90
hashKeyFunction · 0.90
getMutationCacheMethod · 0.80
notifyMethod · 0.45

Tested by

no test coverage detected