(id = '')
| 25 | * ``` |
| 26 | */ |
| 27 | export function useQueryClient(id = ''): QueryClient { |
| 28 | // ensures that `inject()` can be used |
| 29 | if (!hasInjectionContext()) { |
| 30 | throw new Error( |
| 31 | 'vue-query hooks can only be used inside setup() function or functions that support injection context.', |
| 32 | ) |
| 33 | } |
| 34 | |
| 35 | const key = getClientKey(id) |
| 36 | const queryClient = inject<QueryClient>(key) |
| 37 | |
| 38 | if (!queryClient) { |
| 39 | throw new Error( |
| 40 | "No 'queryClient' found in Vue context, use 'VueQueryPlugin' to properly initialize the library.", |
| 41 | ) |
| 42 | } |
| 43 | |
| 44 | return queryClient |
| 45 | } |
no test coverage detected