Skip to content

Commit c0fde8b

Browse files
authored
docs: fix nuxt usage (#226)
1 parent ad4cb0f commit c0fde8b

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import type { DehydratedState, VueQueryPluginOptions} from 'vue-query'
12
import {
23
VueQueryPlugin,
3-
VueQueryPluginOptions,
44
QueryClient,
55
hydrate,
66
dehydrate,
77
} from "vue-query";
8+
// Nuxt 3 app aliases
9+
import { useState} from '#app'
810

911
export default (nuxt) => {
1012
// Modify your Vue Query global settings here
@@ -14,18 +16,19 @@ export default (nuxt) => {
1416
const options: VueQueryPluginOptions = { queryClient };
1517

1618
nuxt.vueApp.use(VueQueryPlugin, options);
19+
const vueQueryClient = useState<DehydratedState | null>('vue-query')
1720

1821
// @ts-expect-error Nuxt process variable
1922
if (process.server) {
20-
nuxt.hooks.hook("app:rendered", () => {
21-
nuxt.nuxtState["vue-query"] = dehydrate(queryClient);
22-
});
23+
nuxt.hooks.hook('app:rendered', () => {
24+
vueQueryClient.value = dehydrate(queryClient)
25+
})
2326
}
2427

2528
// @ts-expect-error Nuxt process variable
2629
if (process.client) {
27-
nuxt.hooks.hook("app:created", () => {
28-
hydrate(queryClient, nuxt.nuxtState["vue-query"]);
29-
});
30+
nuxt.hooks.hook('app:created', () => {
31+
hydrate(queryClient, vueQueryClient.value)
32+
})
3033
}
3134
};

0 commit comments

Comments
 (0)