MCPcopy
hub / github.com/TanStack/query / useBaseQuery

Function useBaseQuery

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

Source from the content-addressed store, hash-verified

25import type { UseBaseQueryOptions } from './types'
26
27export function useBaseQuery<
28 TQueryFnData,
29 TError,
30 TData,
31 TQueryData,
32 TQueryKey extends QueryKey,
33>(
34 options: UseBaseQueryOptions<
35 TQueryFnData,
36 TError,
37 TData,
38 TQueryData,
39 TQueryKey
40 >,
41 Observer: typeof QueryObserver,
42 queryClient?: QueryClient,
43): QueryObserverResult<TData, TError> {
44 if (process.env.NODE_ENV !== 'production') {
45 if (typeof options !== 'object' || Array.isArray(options)) {
46 throw new Error(
47 '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',
48 )
49 }
50 }
51
52 const isRestoring = useIsRestoring()
53 const errorResetBoundary = useQueryErrorResetBoundary()
54 const client = useQueryClient(queryClient)
55 const defaultedOptions = client.defaultQueryOptions(options)
56
57 ;(client.getDefaultOptions().queries as any)?._experimental_beforeQuery?.(
58 defaultedOptions,
59 )
60
61 if (process.env.NODE_ENV !== 'production') {
62 if (!defaultedOptions.queryFn) {
63 console.error(
64 `[${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`,
65 )
66 }
67 }
68
69 // Make sure results are optimistically set in fetching state before subscribing or updating options
70 defaultedOptions._optimisticResults = isRestoring
71 ? 'isRestoring'
72 : 'optimistic'
73
74 ensureSuspenseTimers(defaultedOptions)
75 ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary)
76
77 useClearResetErrorBoundary(errorResetBoundary)
78
79 // this needs to be invoked before creating the Observer because that can create a cache entry
80 const isNewCacheEntry = !client
81 .getQueryCache()
82 .get(defaultedOptions.queryHash)
83
84 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
willFetchFunction · 0.90
defaultQueryOptionsMethod · 0.80
getDefaultOptionsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…