Open History to see the last commit
1---
2id: useQueryClient
3title: useQueryClient
4---
5β
6<!-- DO NOT EDIT: this page is autogenerated from the type comments -->
7β
8```ts
9function useQueryClient(queryClient?: QueryClient): QueryClient;
10```
11β
12Defined in: [packages/svelte-query/src/useQueryClient.ts:24](https://github.com/TanStack/query/blob/main/packages/svelte-query/src/useQueryClient.ts#L24)
13β
14The `useQueryClient` function returns the current `QueryClient` instance.
15β
16## Parameters
17β
18### queryClient?
19β
20[`QueryClient`](../classes/QueryClient.md)
21β
22Use this to use a custom `QueryClient`. Otherwise, the one from the nearest context will
23be used.
24β
25## Returns
26β
27[`QueryClient`](../classes/QueryClient.md)
28β
29The current `QueryClient` instance.
30β
31## Throws
32β
33If no `queryClient` argument is passed and no `QueryClientProvider` is found in the
34component tree.
35β
36## Example
37β
38```svelte
39<script lang="ts">
40 import { useQueryClient } from '@tanstack/svelte-query'
41β
42 const queryClient = useQueryClient()
43β
44 function refreshPosts() {
45 queryClient.invalidateQueries({ queryKey: ['posts'] })
46 }
47</script>
48```