最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

reactjs - how to use React Query (TANStack) in next js server components? - Stack Overflow

programmeradmin2浏览0评论

A lot of people are saying that use React Query for efficient data retrieval. But to use useQuery hook I have to make every component "client component" then what would be the purpose of SSR and SSG in Nextjs.

Please clear my confusion

I was just looking at the docs.

A lot of people are saying that use React Query for efficient data retrieval. But to use useQuery hook I have to make every component "client component" then what would be the purpose of SSR and SSG in Nextjs.

Please clear my confusion

I was just looking at the docs.

Share Improve this question asked Mar 2 at 8:16 Yaseen JabirYaseen Jabir 1
Add a comment  | 

1 Answer 1

Reset to default 0

In Next.js, you are allowed to pass server components as props of client component.

For example this code:

<ClientComponent>
   <ServerComponent />
</ClientComponent>

You can view the docs Server and Client Composition Patterns – Supported Pattern: Passing Server Components to Client Components as Props

In human terms, you can see it as Next.js send both components back to the client at the same time. One already rendered by the server, and one for client to render for themselves. Then, the client can piece those two components according to the layout.

So it allows for SSR while also allowing for client-side dependency injection like <Providers> or in this case <QueryClientProvider />

发布评论

评论列表(0)

  1. 暂无评论