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