Open History to see the last commit
1import { getContext, setContext } from 'svelte'
2import type { QueryClient } from '@tanstack/query-core'
3β
4const _contextKey = '$$_queryClient'
5β
6/** Retrieves a Client from Svelte's context */
7export const getQueryClientContext = (): QueryClient => {
8 const client = getContext(_contextKey)
9 if (!client) {
10 throw new Error(
11 'No QueryClient was found in Svelte context. Did you forget to wrap your component with QueryClientProvider?',
12 )
13 }
14β
15 return client as QueryClient
16}
17β
18/** Sets a QueryClient on Svelte's context */
19export const setQueryClientContext = (client: QueryClient): void => {
20 setContext(_contextKey, client)
21}