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

Method setOptions

packages/query-core/src/mutationObserver.ts:96–125  ·  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

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