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

Method mutate

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

* Builds a new `Mutation` in the `MutationCache` using the observer's * current options, detaches this observer from any previously observed * mutation, attaches it to the new one, and executes it with the given * variables. * * The optional per-call `options` (`onSuccess`/`onError`/`

(
    variables: TVariables,
    options?: MutateOptions<TData, TError, TVariables, TOnMutateResult>,
  )

Source from the content-addressed store, hash-verified

215 * ```
216 */
217 mutate(
218 variables: TVariables,
219 options?: MutateOptions<TData, TError, TVariables, TOnMutateResult>,
220 ): Promise<TData> {
221 this.#mutateOptions = options
222
223 this.#currentMutation?.removeObserver(this)
224
225 this.#currentMutation = this.#client
226 .getMutationCache()
227 .build(this.#client, this.options)
228
229 this.#currentMutation.addObserver(this)
230
231 return this.#currentMutation.execute(variables)
232 }
233
234 #updateResult(): void {
235 const state =

Calls 5

getMutationCacheMethod · 0.80
executeMethod · 0.80
removeObserverMethod · 0.45
buildMethod · 0.45
addObserverMethod · 0.45

Tested by 11

PageFunction · 0.36
ComponentFunction · 0.36
PageFunction · 0.36
ComponentFunction · 0.36
MutateFunction · 0.36
PageFunction · 0.36
MutatesFunction · 0.36
ComponentFunction · 0.36
MutationsFunction · 0.36
PageFunction · 0.36
MutationFunction · 0.36