Skip to content

Commit d2660a5

Browse files
feat(svelte-5-adapter): require options to be passed as function (#7804)
* fix(svelte-5-adapter): Require options to be passed as function * More fixes * More fixes * Update examples
1 parent 3b2a6e6 commit d2660a5

File tree

44 files changed

+164
-200
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+164
-200
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'}

0 commit comments

Comments
 (0)