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
Copy file name to clipboardexpand all lines: docs/framework/react/guides/advanced-ssr.md
+63
Original file line number
Diff line number
Diff line change
@@ -427,6 +427,69 @@ export default function Posts() {
427
427
428
428
> Note that you could also `useQuery` instead of `useSuspenseQuery`, and the Promise would still be picked up correctly. However, NextJs won't suspend in that case and the component will render in the `pending` status, which also opts out of server rendering the content.
429
429
430
+
If you're using non-JSON data types and serialize the query results on the server, you can specify the `hydrate.transformPromise` option to deserialize the data on the client after the promise is resolved, before the data is put into the cache:
queryFn: () =>getPosts().then(serialize), // <-- serilize the data on the server
470
+
})
471
+
472
+
return (
473
+
<HydrationBoundarystate={dehydrate(queryClient)}>
474
+
<Posts />
475
+
</HydrationBoundary>
476
+
)
477
+
}
478
+
```
479
+
480
+
```tsx
481
+
// app/posts/posts.tsx
482
+
'use client'
483
+
484
+
exportdefaultfunction Posts() {
485
+
const { data } =useSuspenseQuery({ queryKey: ['posts'], queryFn: getPosts })
486
+
487
+
// ...
488
+
}
489
+
```
490
+
491
+
Now, your `getPosts` function can return e.g. `Temporal` datetime objects and the data will be serialized and deserialized on the client, assuming your transformer can serialize and deserialize those data types.
492
+
430
493
For more information, check out the [Next.js App with Prefetching Example](../../examples/nextjs-app-prefetching).
431
494
432
495
## Experimental streaming without prefetching in Next.js
0 commit comments