(
options: UseBaseQueryOptions<
TQueryFnData,
TError,
TData,
TQueryData,
TQueryKey
>,
Observer: typeof QueryObserver,
queryClient?: QueryClient,
)
| 25 | import type { UseBaseQueryOptions } from './types' |
| 26 | |
| 27 | export 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( |
no test coverage detected
searching dependent graphs…