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

Method reducer

packages/query-core/src/mutation.ts:472–526  ·  view source on GitHub ↗
(
      state: MutationState<TData, TError, TVariables, TOnMutateResult>,
    )

Source from the content-addressed store, hash-verified

470
471 #dispatch(action: Action<TData, TError, TVariables, TOnMutateResult>): void {
472 const reducer = (
473 state: MutationState<TData, TError, TVariables, TOnMutateResult>,
474 ): MutationState<TData, TError, TVariables, TOnMutateResult> => {
475 switch (action.type) {
476 case 'failed':
477 return {
478 ...state,
479 failureCount: action.failureCount,
480 failureReason: action.error,
481 }
482 case 'pause':
483 return {
484 ...state,
485 isPaused: true,
486 }
487 case 'continue':
488 return {
489 ...state,
490 isPaused: false,
491 }
492 case 'pending':
493 return {
494 ...state,
495 context: action.context,
496 data: undefined,
497 failureCount: 0,
498 failureReason: null,
499 error: null,
500 isPaused: action.isPaused,
501 status: 'pending',
502 variables: action.variables,
503 submittedAt: Date.now(),
504 }
505 case 'success':
506 return {
507 ...state,
508 data: action.data,
509 failureCount: 0,
510 failureReason: null,
511 error: null,
512 status: 'success',
513 isPaused: false,
514 }
515 case 'error':
516 return {
517 ...state,
518 data: undefined,
519 error: action.error,
520 failureCount: state.failureCount + 1,
521 failureReason: action.error,
522 isPaused: false,
523 status: 'error',
524 }
525 }
526 }
527 this.state = reducer(this.state)
528
529 notifyManager.batch(() => {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected