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

useQueryClient.md

51 lines1.1 KB

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'] })
50</script>
51```