Open History to see the last commit
1import { getCurrentInstance, inject } from 'vue-demi'
2β
3import { getClientKey } from './utils'
4import type { QueryClient } from './queryClient'
5β
6export function useQueryClient(id = ''): QueryClient {
7 const key = getClientKey(id)
8 const queryClient = inject<QueryClient | null>(key, null)
9β
10 if (!queryClient) {
11 const vm = getCurrentInstance()?.proxy
12β
13 if (!vm) {
14 throw new Error(
15 'vue-query hooks can only be used inside setup() function.',
16 )
17 }
18β
19 throw new Error(
20 "No 'queryClient' found in Vue context, use 'VueQueryPlugin' to properly initialize the library.",
21 )
22 }
23β
24 return queryClient
25}