TanStackT
TanStack3y ago
2 replies
foolish-indigo

What is the right way to import queryClient with SSR?

Hey,

I am kinda confused what is the right way to access the QueryClient object in Svelte?

I found two options:

1. Getting it from "hook"
import { useQueryClient } from '@tanstack/svelte-query';

const queryClient = useQueryClient();


2. Accessing it from page data
const queryClient = $page.data.queryClient;
// or
$: queryClient = $page.data.queryClient;


Both of these examples have QueryClientProvider in top root layout.
<QueryClientProvider client={queryClient}>
  <slot />
</QueryClientProvider>
Was this page helpful?