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

useQueryClient.md

49 lines1.1 KB

1---
2id: useQueryClient
3title: useQueryClient
4redirect_from:
5 - framework/vue/reference/useQueryClient
6---
7​
8```ts
9function useQueryClient(id?: string): QueryClient;
10```
11​
12Defined in: [packages/vue-query/src/useQueryClient.ts:27](https://github.com/TanStack/query/blob/main/packages/vue-query/src/useQueryClient.ts#L27)
13​
14Retrieves the `QueryClient` installed by `VueQueryPlugin`, via Vue's `inject`. Must be called inside
15`setup()` or another function that supports an injection context.
16​
17## Parameters
18​
19### id?
20​
21`string` = `''`
22​
23The `queryClientKey` passed to `VueQueryPlugin` β€” only needed when multiple `QueryClient`s are
24installed in the same app.
25​
26## Returns
27​
28[`QueryClient`](../classes/QueryClient.md)
29​
30The installed `QueryClient`.
31​
32## Throws
33​
34If called outside an injection context, or if no `QueryClient` was installed via
35`VueQueryPlugin`.
36​
37## Example
38​
39```vue
40<script setup lang="ts">
41import { useQueryClient } from '@tanstack/vue-query'
42​
43const queryClient = useQueryClient()
44​
45function invalidate() {
46 queryClient.invalidateQueries({ queryKey: ['todos'] })
48</script>
49```