Skip to content

Commit 6ac294c

Browse files
Update examples
1 parent 9ffbaf7 commit 6ac294c

File tree

23 files changed

+51
-45
lines changed

23 files changed

+51
-45
lines changed

examples/svelte/basic/src/lib/Post.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
66
const { postId }: { postId: number } = $props()
77
8-
const post = createQuery<Post>({
8+
const post = createQuery<Post>(() => ({
99
queryKey: ['post', postId],
1010
queryFn: () => getPostById(postId),
11-
})
11+
}))
1212
</script>
1313

1414
<div>

examples/svelte/basic/src/lib/Posts.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
const posts = createQuery<
1010
{ id: number; title: string; body: string }[],
1111
Error
12-
>({
12+
>(() => ({
1313
queryKey: ['posts', limit],
1414
queryFn: () => getPosts(limit),
15-
})
15+
}))
1616
</script>
1717

1818
<div>

examples/svelte/load-more-infinite-scroll/src/lib/LoadMore.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
const fetchPlanets = async ({ pageParam = 1 }) =>
77
await fetch(`${endPoint}/planets/?page=${pageParam}`).then((r) => r.json())
88
9-
const query = createInfiniteQuery({
9+
const query = createInfiniteQuery(() => ({
1010
queryKey: ['planets'],
1111
queryFn: ({ pageParam }) => fetchPlanets({ pageParam }),
1212
initialPageParam: 1,
@@ -20,7 +20,7 @@
2020
}
2121
return undefined
2222
},
23-
})
23+
}))
2424
</script>
2525

2626
{#if query.isPending}

examples/svelte/optimistic-updates/src/routes/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@
3636
}),
3737
}).then((res) => res.json())
3838
39-
const todos = createQuery<Todos>({
39+
const todos = createQuery<Todos>(() => ({
4040
queryKey: ['optimistic'],
4141
queryFn: fetchTodos,
42-
})
42+
}))
4343
4444
const addTodoMutation = createMutation({
4545
mutationFn: createTodo,

examples/svelte/playground/src/routes/AddTodo.svelte

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@
2020
() => {
2121
if (Math.random() < errorRate.value) {
2222
return reject(
23-
new Error(JSON.stringify({ postTodo: { name, notes } }, null, 2)),
23+
new Error(
24+
JSON.stringify(
25+
{ postTodo: { name: $state.snapshot(name), notes } },
26+
null,
27+
2,
28+
),
29+
),
2430
)
2531
}
2632
const todo = { name, notes, id: id.value }

examples/svelte/playground/src/routes/EditTodo.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
}
5656
list.value = list.value.map((d) => {
5757
if (d.id === todo.id) {
58-
return todo
58+
return $state.snapshot(todo)
5959
}
6060
return d
6161
})
@@ -67,11 +67,11 @@
6767
})
6868
}
6969
70-
const query = createQuery({
70+
const query = createQuery(() => ({
7171
queryKey: ['todo', { id: editingIndex.value }],
7272
queryFn: () => fetchTodoById({ id: editingIndex.value || 0 }),
7373
enabled: editingIndex.value !== null,
74-
})
74+
}))
7575
7676
const saveMutation = createMutation({
7777
mutationFn: patchTodo,

examples/svelte/simple/src/lib/Simple.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
forks_count: number
1010
}
1111
12-
const query = createQuery<Repo>({
12+
const query = createQuery<Repo>(() => ({
1313
queryKey: ['repoData'],
1414
queryFn: async () =>
1515
await fetch('https://api.github.com/repos/TanStack/query').then((r) =>
1616
r.json(),
1717
),
18-
})
18+
}))
1919
</script>
2020

2121
<h1>Simple</h1>

examples/svelte/ssr/src/lib/Post.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
66
const { postId }: { postId: number } = $props()
77
8-
const post = createQuery<Post>({
8+
const post = createQuery<Post>(() => ({
99
queryKey: ['post', postId],
1010
queryFn: () => api().getPostById(postId),
11-
})
11+
}))
1212
</script>
1313

1414
<div>

examples/svelte/ssr/src/lib/Posts.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
const posts = createQuery<
1010
{ id: number; title: string; body: string }[],
1111
Error
12-
>({
12+
>(() => ({
1313
queryKey: ['posts', limit],
1414
queryFn: () => api().getPosts(limit),
15-
})
15+
}))
1616
</script>
1717

1818
<div>

examples/svelte/star-wars/src/routes/characters/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
return await res.json()
77
}
88
9-
const query = createQuery({
9+
const query = createQuery(() => ({
1010
queryKey: ['characters'],
1111
queryFn: getCharacters,
12-
})
12+
}))
1313
</script>
1414

1515
{#if query.status === 'pending'}

examples/svelte/star-wars/src/routes/characters/[characterId]/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
return await res.json()
1313
}
1414
15-
const query = createQuery({
15+
const query = createQuery(() => ({
1616
queryKey: ['character', data.params.characterId],
1717
queryFn: getCharacter,
18-
})
18+
}))
1919
</script>
2020

2121
{#if query.status === 'pending'}

examples/svelte/star-wars/src/routes/characters/[characterId]/Film.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
return await res.json()
99
}
1010
11-
const query = createQuery({
11+
const query = createQuery(() => ({
1212
queryKey: ['film', filmId],
1313
queryFn: getFilm,
14-
})
14+
}))
1515
</script>
1616

1717
{#if query.status === 'success'}

examples/svelte/star-wars/src/routes/characters/[characterId]/Homeworld.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
return await res.json()
99
}
1010
11-
const query = createQuery({
11+
const query = createQuery(() => ({
1212
queryKey: ['homeworld', homeworldId],
1313
queryFn: getHomeworld,
14-
})
14+
}))
1515
</script>
1616

1717
{#if query.status === 'success'}

examples/svelte/star-wars/src/routes/films/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
return await res.json()
77
}
88
9-
const query = createQuery({
9+
const query = createQuery(() => ({
1010
queryKey: ['films'],
1111
queryFn: getFilms,
12-
})
12+
}))
1313
</script>
1414

1515
{#if query.status === 'pending'}

examples/svelte/star-wars/src/routes/films/[filmId]/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
return await res.json()
1212
}
1313
14-
const query = createQuery({
14+
const query = createQuery(() => ({
1515
queryKey: ['film', data.params.filmId],
1616
queryFn: getFilm,
17-
})
17+
}))
1818
</script>
1919

2020
{#if query.status === 'pending'}

examples/svelte/star-wars/src/routes/films/[filmId]/Character.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
return await res.json()
99
}
1010
11-
const query = createQuery({
11+
const query = createQuery(() => ({
1212
queryKey: ['character', characterId],
1313
queryFn: getCharacter,
14-
})
14+
}))
1515
</script>
1616

1717
{#if query.status === 'success'}

packages/svelte-query-persist-client/tests/AwaitOnSuccess/AwaitOnSuccess.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
55
let { states }: { states: Array<string> } = $props()
66
7-
const query = createQuery({
7+
const query = createQuery(() => ({
88
queryKey: ['test'],
99
queryFn: async () => {
1010
states.push('fetching')
1111
await sleep(5)
1212
states.push('fetched')
1313
return 'fetched'
1414
},
15-
})
15+
}))
1616
</script>
1717

1818
<div>{query.data}</div>

packages/svelte-query-persist-client/tests/FreshData/FreshData.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
fetched: boolean
1313
} = $props()
1414
15-
const query = createQuery({
15+
const query = createQuery(() => ({
1616
queryKey: ['test'],
1717
queryFn: async () => {
1818
fetched = true
@@ -21,7 +21,7 @@
2121
},
2222
2323
staleTime: Infinity,
24-
})
24+
}))
2525
2626
$effect(() => {
2727
states.value = [...untrack(() => states.value), $state.snapshot(query)]

packages/svelte-query-persist-client/tests/InitialData/InitialData.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
let { states }: { states: { value: Array<StatusResult<string>> } } = $props()
88
9-
const query = createQuery({
9+
const query = createQuery(() => ({
1010
queryKey: ['test'],
1111
queryFn: async () => {
1212
await sleep(5)
@@ -17,7 +17,7 @@
1717
// make sure that initial data is older than the hydration data
1818
// otherwise initialData would be newer and takes precedence
1919
initialDataUpdatedAt: 1,
20-
})
20+
}))
2121
2222
$effect(() => {
2323
states.value = [...untrack(() => states.value), $state.snapshot(query)]

packages/svelte-query-persist-client/tests/OnSuccess/OnSuccess.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
import { createQuery } from '@tanstack/svelte-query'
33
import { sleep } from '../utils.svelte'
44
5-
const query = createQuery({
5+
const query = createQuery(() => ({
66
queryKey: ['test'],
77
queryFn: async () => {
88
await sleep(5)
99
return 'fetched'
1010
},
11-
})
11+
}))
1212
</script>
1313

1414
<div>{query.data}</div>

packages/svelte-query-persist-client/tests/RemoveCache/RemoveCache.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
import { createQuery } from '@tanstack/svelte-query'
33
import { sleep } from '../utils.svelte'
44
5-
const query = createQuery({
5+
const query = createQuery(() => ({
66
queryKey: ['test'],
77
queryFn: async () => {
88
await sleep(5)
99
return 'fetched'
1010
},
11-
})
11+
}))
1212
</script>
1313

1414
<div>{query.data}</div>

packages/svelte-query-persist-client/tests/RestoreCache/RestoreCache.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
77
let { states }: { states: { value: Array<StatusResult<string>> } } = $props()
88
9-
const query = createQuery({
9+
const query = createQuery(() => ({
1010
queryKey: ['test'],
1111
queryFn: async () => {
1212
await sleep(5)
1313
return 'fetched'
1414
},
15-
})
15+
}))
1616
1717
$effect(() => {
1818
states.value = [...untrack(() => states.value), $state.snapshot(query)]

packages/svelte-query-persist-client/tests/UseQueries/UseQueries.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
let { states }: { states: { value: Array<StatusResult<string>> } } = $props()
88
99
const queries = createQueries({
10-
queries: [
10+
queries: () => [
1111
{
1212
queryKey: ['test'],
1313
queryFn: async (): Promise<string> => {

0 commit comments

Comments
 (0)