Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(svelte-query): Add recommended defaults to prefetchQuery setup #4815

Merged
merged 2 commits into from Jan 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/config.json
Expand Up @@ -695,13 +695,13 @@
"label": "Installation",
"to": "svelte/installation"
},
{
"label": "Reactivity",
"to": "svelte/reactivity"
},
{
"label": "SSR & SvelteKit",
"to": "svelte/ssr"
},
{
"label": "Reactivity",
"to": "svelte/reactivity"
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion docs/svelte/overview.md
Expand Up @@ -11,7 +11,7 @@ Include the QueryClientProvider near the root of your project:

```markdown
<script lang="ts">
import { QueryClientProvider, QueryClient } from '@tanstack/svelte-query'
import { QueryClient, QueryClientProvider } from '@tanstack/svelte-query'
import Example from './lib/Example.svelte'

const queryClient = new QueryClient()
Expand Down
14 changes: 12 additions & 2 deletions docs/svelte/ssr.md
Expand Up @@ -9,10 +9,12 @@ SvelteKit defaults to rendering routes with SSR. Because of this, you need to di

The recommended way to achieve this is to use the `browser` module from SvelteKit in your `QueryClient` object. This will not disable `queryClient.prefetchQuery()`, which is used in one of the solutions below.

**src/routes/+layout.svelte**

```markdown
<script lang="ts">
import { browser } from '$app/environment'
import { QueryClient } from '@tanstack/svelte-query'
import { QueryClient, QueryClientProvider } from '@tanstack/svelte-query'

const queryClient = new QueryClient({
defaultOptions: {
Expand Down Expand Up @@ -83,11 +85,19 @@ Svelte Query supports prefetching queries on the server. Using this setup below,
**src/routes/+layout.ts**

```ts
import { browser } from '$app/environment'
import { QueryClient } from '@tanstack/svelte-query'
import type { LayoutLoad } from './$types'

export const load: LayoutLoad = async () => {
const queryClient = new QueryClient()
const queryClient = new QueryClient({
defaultOptions: {
queries: {
enabled: browser,
},
},
})

return { queryClient }
}
```
Expand Down