Client Context vs Server Side Props Drilling
Unanswered
Britannia Petite posted this in #help-forum
Britannia PetiteOP
I have a rather general qn because I am not an expert on the App router.
We have an App that starts with Server Components and then on certain subpages we introduce client side stuff at some point.
If I have a user for example, would I fetch this user on the server side and "drill it down" all the way to the client components? Seems like an antipattern.
My take would be to create a context at the root and pass it there to access from anywhere in my app on the client side. However, then I am not sure about the sync state between client and server side for that user endpoint.
Is there a go to strategy here? Thanks so much for any pointers 🙂
We have an App that starts with Server Components and then on certain subpages we introduce client side stuff at some point.
If I have a user for example, would I fetch this user on the server side and "drill it down" all the way to the client components? Seems like an antipattern.
My take would be to create a context at the root and pass it there to access from anywhere in my app on the client side. However, then I am not sure about the sync state between client and server side for that user endpoint.
Is there a go to strategy here? Thanks so much for any pointers 🙂
3 Replies
you can use tools like useQuery to prefetch it in the server component and use it anywhere in that tree https://tanstack.com/query/latest/docs/framework/react/guides/advanced-ssr
Britannia PetiteOP
Thanks I am actually doing that. My qn is more about how to "drill it down" to client side components. I fetch the user in the root layout and pass it down. But I do not want to drill it to 4-5 child components...
And i could obv do client side fetches but not sure if I will run into syncing issues etc.