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

Function useBaseQuery

packages/react-query/src/useBaseQuery.ts:26–140  ·  view source on GitHub ↗
(
  options: UseBaseQueryOptions<
    TQueryFnData,
    TError,
    TData,
    TQueryData,
    TQueryKey
  >,
  Observer: typeof QueryObserver,
  queryClient?: QueryClient,
)

Source from the content-addressed store, hash-verified

24import type { UseBaseQueryOptions } from './types'
25
26export function useBaseQuery<
27 TQueryFnData,
28 TError,
29 TData,
30 TQueryData,
31 TQueryKey extends QueryKey,
32>(
33 options: UseBaseQueryOptions<
34 TQueryFnData,
35 TError,
36 TData,
37 TQueryData,
38 TQueryKey
39 >,
40 Observer: typeof QueryObserver,
41 queryClient?: QueryClient,
42): QueryObserverResult<TData, TError> {
43 if (process.env.NODE_ENV !== 'production') {
44 if (typeof options !== 'object' || Array.isArray(options)) {
45 throw new Error(
46 'Bad argument type. Starting with v5, only the "Object" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object',
47 )
48 }
49 }
50
51 const isRestoring = useIsRestoring()
52 const errorResetBoundary = useQueryErrorResetBoundary()
53 const client = useQueryClient(queryClient)
54 const defaultedOptions = client.defaultQueryOptions(options)
55
56 const query = client
57 .getQueryCache()
58 .get<TQueryFnData, TError, TQueryData, TQueryKey>(
59 defaultedOptions.queryHash,
60 )
61
62 if (process.env.NODE_ENV !== 'production') {
63 if (!defaultedOptions.queryFn) {
64 console.error(
65 `[${defaultedOptions.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`,
66 )
67 }
68 }
69
70 const subscribed = options.subscribed !== false
71
72 // Make sure results are optimistically set in fetching state before subscribing or updating options
73 defaultedOptions._optimisticResults = isRestoring
74 ? 'isRestoring'
75 : subscribed
76 ? 'optimistic'
77 : undefined
78
79 ensureSuspenseTimers(defaultedOptions)
80 ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary, query)
81 useClearResetErrorBoundary(errorResetBoundary)
82
83 const [observer] = React.useState(

Callers 4

useQueryFunction · 0.90
useSuspenseInfiniteQueryFunction · 0.90
useInfiniteQueryFunction · 0.90
useSuspenseQueryFunction · 0.90

Calls 15

useIsRestoringFunction · 0.90
useQueryClientFunction · 0.90
ensureSuspenseTimersFunction · 0.90
shouldSuspendFunction · 0.90
fetchOptimisticFunction · 0.90
getHasErrorFunction · 0.90
defaultQueryOptionsMethod · 0.80
getMethod · 0.80
getQueryCacheMethod · 0.80

Tested by

no test coverage detected