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

Function fetchState

packages/query-core/src/query.ts:1056–1075  ·  view source on GitHub ↗
(
  data: TData | undefined,
  options: QueryOptions<TQueryFnData, TError, TData, TQueryKey>,
)

Source from the content-addressed store, hash-verified

1054 * @returns The partial query state for a starting fetch.
1055 */
1056export function fetchState<
1057 TQueryFnData,
1058 TError,
1059 TData,
1060 TQueryKey extends QueryKey,
1061>(
1062 data: TData | undefined,
1063 options: QueryOptions<TQueryFnData, TError, TData, TQueryKey>,
1064) {
1065 return {
1066 fetchFailureCount: 0,
1067 fetchFailureReason: null,
1068 fetchStatus: canFetch(options.networkMode) ? 'fetching' : 'paused',
1069 ...(data === undefined &&
1070 ({
1071 error: null,
1072 status: 'pending',
1073 } as const)),
1074 } as const
1075}
1076
1077/**
1078 * Returns the state changes applied when a query receives data.

Callers 2

createResultMethod · 0.90
reducerMethod · 0.85

Calls 1

canFetchFunction · 0.90

Tested by

no test coverage detected