admin管理员组

文章数量:1404927

Out of curiosity, shadcn's sidebar has 'use client' declaration on the top of its component file which includes the declaration of SidebarProvider. From my understanding of nextjs, when a client component is rendered, all of its children are rendered on the client side too. But the shadcn documentation encourages to wrap out entire application with the SidebarProvider. Does this not render our entire app on the client side and kill ssr as a whole?

I am pretty sure this is not the case, but how does this SidebarProvider work under the hood?

Out of curiosity, shadcn's sidebar has 'use client' declaration on the top of its component file which includes the declaration of SidebarProvider. From my understanding of nextjs, when a client component is rendered, all of its children are rendered on the client side too. But the shadcn documentation encourages to wrap out entire application with the SidebarProvider. Does this not render our entire app on the client side and kill ssr as a whole?

I am pretty sure this is not the case, but how does this SidebarProvider work under the hood?

Share Improve this question asked Mar 9 at 7:57 Tenshi MunasingheTenshi Munasinghe 1,2981 gold badge9 silver badges17 bronze badges 1
  • just read the nextjs doc nextjs./docs/app/building-your-application/rendering/… I guess this is fine because the server components are passed as children? – Tenshi Munasinghe Commented Mar 9 at 8:43
Add a comment  | 

1 Answer 1

Reset to default 1

use client does not mean that the server side rendering is gone/killed. As mentioned in this dicussion, client components are also rendered on the server, just that they are also interactive.

How else will we use useEffect and other client side hooks in components, if they do not run on the client once.

And yes, as you already mentioned in the comment that server components can be passed into client components as props. A simpler mental model is explained here

本文标签: javascriptDoes shadcn SidebarProvider render all its children on the client on NextjsStack Overflow