Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

useQueryClient.md

48 lines1.0 KB

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```