SSR in Next 13 app directory using Hydrate #5667
Answered
by
2manoj1
JurajKavka
asked this question in
Q&A
-
Hello I'm setting up react-query SSR in Next 13 app directory useing Hydrate, and I have question, why the // app/getQueryClient.jsx
import { QueryClient } from '@tanstack/react-query'
import { cache } from 'react'
const getQueryClient = cache(() => new QueryClient())
export default getQueryClient If it is used like that and I want to reuse the same function in client component export default function Providers({ children }: { children: React.ReactNode }) {
const [queryClient] = React.useState(
getQueryClient
);
return (
<QueryClientProvider client={queryClient}>
{children}
<ReactQueryDevtools />
</QueryClientProvider>
);
} It breaks SSR in that way, that the content is not rendered in HTML. I can see content in browser but no in raw HTML. What is the reason? Thank You! |
Beta Was this translation helpful? Give feedback.
Answered by
2manoj1
Jul 6, 2023
Replies: 1 comment 2 replies
-
@JurajKavka read this for cache https://nextjs.org/docs/app/building-your-application/data-fetching/caching#react-cache Example with SSR: |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
React Query provider having some client dependency not working with latest Nextjs so create wrapper component with use client.
In SSR we require Singleton client that reason wrap with cache and expose. Otherwise it's creating multiple instances. We require same instance accross application - both SSR and CSR component. Check their docs