Can we use React Query library in server component?
Unanswered
Dwarf Hotot posted this in #help-forum
Dwarf HototOP
Hi All,
I have just started using Next.js. I have a doubt.
I know that we can use hooks and event handlers only in client component and not server component, But Can we use React Query library for fetching api request in a server component of Next.js?
Thanks in advance for your response.
I have just started using Next.js. I have a doubt.
I know that we can use hooks and event handlers only in client component and not server component, But Can we use React Query library for fetching api request in a server component of Next.js?
Thanks in advance for your response.
6 Replies
European sprat
Yes
Dwarf HototOP
I am a bit confused because here in SS( https://chat.vercel.ai/) its showing we can't use React Query in server side rendering.
don't trust the AI on very new matters like this
that being said, i think the best way to combine tanstack query with server components now is to fetch the data in a server component then pass it to tanstack query running in a client component as initial data
@Dwarf Hotot I am a bit confused because here in SS( https://chat.vercel.ai/) its showing we can't use React Query in server side rendering.
European sprat
Check out the react query docs SSR page https://tanstack.com/query/v4/docs/react/guides/ssr