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

Function useBaseQuery

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

Source from the content-addressed store, hash-verified

36 * thrown to the nearest error boundary (see `throwOnError`). While suspending, it throws a promise instead.
37 */
38export function useBaseQuery<
39 TQueryFnData,
40 TError,
41 TData,
42 TQueryData,
43 TQueryKey extends QueryKey,
44>(
45 options: UseBaseQueryOptions<
46 TQueryFnData,
47 TError,
48 TData,
49 TQueryData,
50 TQueryKey
51 >,
52 Observer: typeof QueryObserver,
53 queryClient?: QueryClient,
54): QueryObserverResult<TData, TError> {
55 if (process.env.NODE_ENV !== 'production') {
56 if (typeof options !== 'object' || Array.isArray(options)) {
57 throw new Error(
58 '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',
59 )
60 }
61 }
62
63 const isRestoring = useIsRestoring()
64 const errorResetBoundary = useQueryErrorResetBoundary()
65 const client = useQueryClient(queryClient)
66 const defaultedOptions = client.defaultQueryOptions(options)
67
68 const query = client
69 .getQueryCache()
70 .get<TQueryFnData, TError, TQueryData, TQueryKey>(
71 defaultedOptions.queryHash,
72 )
73
74 if (process.env.NODE_ENV !== 'production') {
75 if (!defaultedOptions.queryFn) {
76 console.error(
77 `[${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`,
78 )
79 }
80 }
81
82 const subscribed = options.subscribed !== false
83
84 // Make sure results are optimistically set in fetching state before subscribing or updating options
85 defaultedOptions._optimisticResults = isRestoring
86 ? 'isRestoring'
87 : subscribed
88 ? 'optimistic'
89 : undefined
90
91 ensureSuspenseTimers(defaultedOptions)
92 ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary, query)
93
94 useClearResetErrorBoundary(errorResetBoundary)
95

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
useSyncExternalStoreFunction · 0.90
shouldSuspendFunction · 0.90
fetchOptimisticFunction · 0.90
getHasErrorFunction · 0.90
defaultQueryOptionsMethod · 0.80
getMethod · 0.80

Tested by

no test coverage detected