Skip to content

Commit 7085bd1

Browse files
docs: correct file extensions to .tsx and add type annotations (TanStack#8259)
* Fix typo: 'hydrate' to 'dehydrate' in documentation * fix: correct file extensions to .tsx and add type annotations * ci: apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 8ae5aed commit 7085bd1

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

docs/framework/react/guides/advanced-ssr.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function getQueryClient() {
6464
}
6565
}
6666

67-
export default function Providers({ children }) {
67+
export default function Providers({ children }: { children: React.ReactNode }) {
6868
// NOTE: Avoid useState when initializing the query client if you don't
6969
// have a suspense boundary between this and the code that may
7070
// suspend because React will throw away the client on the initial
@@ -78,10 +78,14 @@ export default function Providers({ children }) {
7878
```
7979

8080
```tsx
81-
// In Next.js, this file would be called: app/layout.jsx
81+
// In Next.js, this file would be called: app/layout.tsx
8282
import Providers from './providers'
8383

84-
export default function RootLayout({ children }) {
84+
export default function RootLayout({
85+
children,
86+
}: {
87+
children: React.ReactNode
88+
}) {
8589
return (
8690
<html lang="en">
8791
<head />
@@ -100,7 +104,7 @@ This part is pretty similar to what we did in the SSR guide, we just need to spl
100104
Let's next look at how to actually prefetch data and dehydrate and hydrate it. This is what it looked like using the **Next.js pages router**:
101105

102106
```tsx
103-
// pages/posts.jsx
107+
// pages/posts.tsx
104108
import {
105109
dehydrate,
106110
HydrationBoundary,
@@ -157,7 +161,7 @@ export default function PostsRoute({ dehydratedState }) {
157161
Converting this to the app router actually looks pretty similar, we just need to move things around a bit. First, we'll create a Server Component to do the prefetching part:
158162

159163
```tsx
160-
// app/posts/page.jsx
164+
// app/posts/page.tsx
161165
import {
162166
dehydrate,
163167
HydrationBoundary,
@@ -186,7 +190,7 @@ export default async function PostsPage() {
186190
Next, we'll look at what the Client Component part looks like:
187191

188192
```tsx
189-
// app/posts/posts.jsx
193+
// app/posts/posts.tsx
190194
'use client'
191195

192196
export default function Posts() {
@@ -221,7 +225,7 @@ In the SSR guide, we noted that you could get rid of the boilerplate of having `
221225
A nice thing about Server Components is that they can be nested and exist on many levels in the React tree, making it possible to prefetch data closer to where it's actually used instead of only at the top of the application (just like Remix loaders). This can be as simple as a Server Component rendering another Server Component (we'll leave the Client Components out in this example for brevity):
222226

223227
```tsx
224-
// app/posts/page.jsx
228+
// app/posts/page.tsx
225229
import {
226230
dehydrate,
227231
HydrationBoundary,
@@ -246,7 +250,7 @@ export default async function PostsPage() {
246250
)
247251
}
248252

249-
// app/posts/comments-server.jsx
253+
// app/posts/comments-server.tsx
250254
import {
251255
dehydrate,
252256
HydrationBoundary,
@@ -290,7 +294,7 @@ As more frameworks start supporting Server Components, they might have other rou
290294
In the example above, we create a new `queryClient` for each Server Component that fetches data. This is the recommended approach, but if you want to, you can alternatively create a single one that is reused across all Server Components:
291295

292296
```tsx
293-
// app/getQueryClient.jsx
297+
// app/getQueryClient.tsx
294298
import { QueryClient } from '@tanstack/react-query'
295299
import { cache } from 'react'
296300

@@ -310,7 +314,7 @@ Next.js already dedupes requests that utilize `fetch()`, but if you are using so
310314
With Server Components, it's important to think about data ownership and revalidation. To explain why, let's look at a modified example from above:
311315

312316
```tsx
313-
// app/posts/page.jsx
317+
// app/posts/page.tsx
314318
import {
315319
dehydrate,
316320
HydrationBoundary,
@@ -367,7 +371,7 @@ As of React Query v5.40.0, you don't have to `await` all prefetches for this to
367371

368372
To make this work, we have to instruct the `queryClient` to also `dehydrate` pending Queries. We can do this globally, or by passing that option directly to `dehydrate`.
369373

370-
We will also need to move the `getQueryClient()` function out of our `app/providers.jsx` file as we want to use it in our server component and our client provider.
374+
We will also need to move the `getQueryClient()` function out of our `app/providers.tsx` file as we want to use it in our server component and our client provider.
371375

372376
```tsx
373377
// app/get-query-client.ts
@@ -415,7 +419,7 @@ export function getQueryClient() {
415419
Then, all we need to do is provide a `HydrationBoundary`, but we don't need to `await` prefetches anymore:
416420

417421
```tsx
418-
// app/posts/page.jsx
422+
// app/posts/page.tsx
419423
import { dehydrate, HydrationBoundary } from '@tanstack/react-query'
420424
import { getQueryClient } from './get-query-client'
421425
import Posts from './posts'

docs/framework/react/guides/ssr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export default function MyApp({ Component, pageProps }) {
214214
In each route:
215215

216216
```tsx
217-
// pages/posts.jsx
217+
// pages/posts.tsx
218218
import {
219219
dehydrate,
220220
HydrationBoundary,

0 commit comments

Comments
 (0)