Skip to content

Commit 111167c

Browse files
committed
docs: update vite-ssr example
1 parent 9092a63 commit 111167c

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

docs/guides/ssr.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,26 +148,25 @@ Sync VueQuery client state with [vite-ssr](https://github.com/frandiox/vite-ssr)
148148
// main.js (entry point)
149149
import App from "./App.vue";
150150
import viteSSR from "vite-ssr/vue";
151-
import { QueryClient, hydrate, dehydrate, VUE_QUERY_CLIENT } from "vue-query";
151+
import { QueryClient, VueQueryPlugin, hydrate, dehydrate } from "vue-query";
152152

153153
export default viteSSR(App, { routes: [] }, ({ app, initialState }) => {
154154
// -- This is Vite SSR main hook, which is called once per request
155155

156156
// Create a fresh VueQuery client
157-
const client = new QueryClient();
157+
const queryClient = new QueryClient();
158158

159159
// Sync initialState with the client state
160160
if (import.meta.env.SSR) {
161161
// Indicate how to access and serialize VueQuery state during SSR
162-
initialState.vueQueryState = { toJSON: () => dehydrate(client) };
162+
initialState.vueQueryState = { toJSON: () => dehydrate(queryClient) };
163163
} else {
164164
// Reuse the existing state in the browser
165-
hydrate(client, initialState.vueQueryState);
165+
hydrate(queryClient, initialState.vueQueryState);
166166
}
167167

168168
// Mount and provide the client to the app components
169-
client.mount();
170-
app.provide(VUE_QUERY_CLIENT, client);
169+
app.use(VueQueryPlugin, { queryClient });
171170
});
172171
```
173172

0 commit comments

Comments
 (0)