UNPKG

@tanstack/react-query

Version:

Hooks for managing, caching and syncing asynchronous and remote data in React

1 lines 1.05 kB
{"version":3,"file":"usePrefetchQuery.cjs","names":["useQueryClient","noop"],"sources":["../../src/usePrefetchQuery.tsx"],"sourcesContent":["import { noop } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\n\nimport type { DefaultError, QueryClient, QueryKey } from '@tanstack/query-core'\nimport type { UsePrefetchQueryOptions } from './types'\n\nexport function usePrefetchQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UsePrefetchQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n queryClient?: QueryClient,\n): void {\n const client = useQueryClient(queryClient)\n\n if (!client.getQueryState(options.queryKey)) {\n void client.query(options).catch(noop)\n }\n}\n"],"mappings":";;;;AAMA,SAAgB,iBAOd,SAOA,aACM;CACN,MAAM,SAASA,4BAAAA,eAAe,WAAW;CAEzC,IAAI,CAAC,OAAO,cAAc,QAAQ,QAAQ,GACxC,OAAY,MAAM,OAAO,CAAC,CAAC,MAAMC,qBAAAA,IAAI;AAEzC"}