Next.js Discord

Discord Forum

hooks in server side rendered page

Unanswered
Odorous house ant posted this in #help-forum
Open in Discord
Odorous house antOP
what's the point of implementing SSR pages if you need to use "use client" anytime you need to use react hooks? I have a page here that requires interactivity with the user, but the way how I implemented it is the page itself is SSR, but all the components on the page are client rendered. it now makes me wonder what's even the point of SSR if majority of the pages require interact with the user, which then require using react hooks to update the interface. or am i doing something wrong?

15 Replies

What you are doing is not wrong but your understanding of client component is incorrect
The client components are still prerendered on server
if you are back from <v13 days, you might know that you were able to use hooks in normal pages but cannot access browser APIs outside of useEffect thats because the page was pre-rendered on the server
same thing happens here
"use client" does not mean that the page is only rendered on client
Odorous house antOP
sorry yeah, you're right. pages are still rendered on server, and then you have other codes like fetching data that is done on the client side, correct?
ideally, all the data fetching should be done on server
but there are usecases where that's not possible
say infinite scroll
then you got no choice
Odorous house antOP
but my page has a submission feature, how would i go implement that using ssr?
the user clicks on submit and then page needs to update itself.
you call an api/server action, it does the job and either returns you with data you need to update the page or you/your server action revalidates the page to get latest data
Odorous house antOP
hmmm ok
thanks!