Skip to content

Commit

Permalink
docs(svelte-query): Add recommended defaults to prefetchQuery setup (#…
Browse files Browse the repository at this point in the history
…4815)

* Add recommended defaults to prefetch example

* Move SSR docs up in sidebar
  • Loading branch information
lachlancollins committed Jan 14, 2023
1 parent 832d4fb commit 86161ca
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
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

0 comments on commit 86161ca

Please sign in to comment.