Skip to content

Commit 8ab82dc

Browse files
committed
feat: Add suspense handling to examples
Fixes #22
1 parent a22aa0a commit 8ab82dc

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

examples/minimal/app.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ const getUsers = async () => {
33
return await $fetch('https://jsonplaceholder.typicode.com/users')
44
}
55
6-
const { isPending: isPending, data: users } = useQuery({
6+
const { isPending: isPending, data: users, suspense } = useQuery({
77
queryKey: ['users'],
88
queryFn: getUsers,
99
})
10+
11+
onServerPrefetch(async () => {
12+
await suspense()
13+
})
1014
</script>
1115

1216
<template>

playground/app/app.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const getPosts = async (userId) => {
1212
return await $fetch(url, { method: 'GET', params: { userId } })
1313
}
1414
15-
const { isPending: isUsersPending, data: users } = useQuery({
15+
const { isPending: isUsersPending, data: users, suspense } = useQuery({
1616
queryKey: ['users'],
1717
queryFn: getUsers,
1818
})
@@ -42,6 +42,10 @@ const { mutate: addPost, isPending: isMutationPending } = useMutation({
4242
},
4343
})
4444
45+
onServerPrefetch(async () => {
46+
await suspense()
47+
})
48+
4549
function selectUser(user) {
4650
selectedUser.value = user
4751
}

0 commit comments

Comments
 (0)