Skip to content

Commit 17661f6

Browse files
Simplify load method, fix syntax highlighting (#5844)
* Simplify load method, fix syntax highlighting SvelteKit now automatically infers the type of an exported load method, so no need to manually define it. Also, Github has an ongoing issue with the Svelte syntax highlighting so using `html` is a good fallback. * Change back to using svelte for code blocks --------- Co-authored-by: Lachlan Collins <1667261+lachlancollins@users.noreply.github.com>
1 parent d4c9f42 commit 17661f6

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

docs/svelte/ssr.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ If you wish to view the ideal SSR setup, please have a look at the [SSR example]
4242
Together with SvelteKit's [`load`](https://kit.svelte.dev/docs/load), you can pass the data loaded server-side into `createQuery`'s' `initialData` option:
4343

4444
**src/routes/+page.ts**
45-
```ts
46-
import type { PageLoad } from './$types'
4745

48-
export const load: PageLoad = async () => {
46+
```ts
47+
export async function load() {
4948
const posts = await getPosts()
5049
return { posts }
5150
}
5251
```
5352

5453
**src/routes/+page.svelte**
54+
5555
```svelte
5656
<script>
5757
import { createQuery } from '@tanstack/svelte-query'
@@ -88,7 +88,7 @@ Svelte Query supports prefetching queries on the server. Using this setup below,
8888
import { browser } from '$app/environment'
8989
import { QueryClient } from '@tanstack/svelte-query'
9090

91-
export const load = async () => {
91+
export async function load() {
9292
const queryClient = new QueryClient({
9393
defaultOptions: {
9494
queries: {
@@ -119,9 +119,7 @@ export const load = async () => {
119119
**src/routes/+page.ts**
120120

121121
```ts
122-
import type { PageLoad } from './$types'
123-
124-
export const load: PageLoad = async ({ parent, fetch }) => {
122+
export async function load({ parent, fetch }) {
125123
const { queryClient } = await parent()
126124

127125
// You need to use the SvelteKit fetch function here

0 commit comments

Comments
 (0)