You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now you are ready to prefetch some data in your pages with either [`getStaticProps`](https://nextjs.org/docs/basic-features/data-fetching#getstaticprops-static-generation) (for SSG) or [`getServerSideProps`](https://nextjs.org/docs/basic-features/data-fetching#getserversideprops-server-side-rendering) (for SSR). From React Query's perspective, these integrate in the same way, `getStaticProps` is shown below.
76
75
77
-
- Create a new `QueryCache` and `QueryClient` instance for each page request
76
+
- Create a `QueryClient` instance for each page request
78
77
- Prefetch the data using the clients `prefetchQuery` method and wait for it to complete
79
78
- Use `dehydrate` to dehydrate the query cache and pass it to the page via the `dehydratedState` prop. This is the same prop that the cache will be picked up from in your `_app.js`
@@ -119,10 +117,9 @@ This guide is at-best, a high level overview of how SSR with React Query should
119
117
120
118
### On the Server
121
119
122
-
- Create a new `QueryCache` instance
123
120
- Create a new `QueryClient` instance
124
121
- Using the client, prefetch any data you need
125
-
- Dehydrate the cache
122
+
- Dehydrate the client
126
123
- Render your app with the client provider and also **using the dehydrated state. This is extremely important! You must render both server and client using the same dehydrated state to ensure hydration on the client produces the exact same markup as the server.**
127
124
- Serialize and embed the dehydrated cache to be sent to the client with the HTML
128
125
@@ -132,10 +129,9 @@ This guide is at-best, a high level overview of how SSR with React Query should
- Parse the dehydrated cache state that was sent to the client with the HTML
165
-
- Create a new `QueryCache` instance
166
161
- Create a new `QueryClient` instance
167
162
- Render your app with the client provider and also **using the dehydrated state. This is extremely important! You must render both server and client using the same dehydrated state to ensure hydration on the client produces the exact same markup as the server.**
0 commit comments