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

Method reducer

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected