How to make one component use cookie while still get static rendering.
Unanswered
Dwarf Crocodile posted this in #help-forum
Dwarf CrocodileOP
I want to show the login button and if the user is already logged in then show his email. I want to do on static pages like about etc because it'll share the same header.
Nextjs shows error I'm trying to access cookies() so pages become dynamic.
I resolved by making route.ts which will return user and making fetch call to get in client components. Is it correct?
Nextjs shows error I'm trying to access cookies() so pages become dynamic.
I resolved by making route.ts which will return user and making fetch call to get in client components. Is it correct?
8 Replies
@Dwarf Crocodile I want to show the login button and if the user is already logged in then show his email. I want to do on static pages like about etc because it'll share the same header.
Nextjs shows error I'm trying to access cookies() so pages become dynamic.
I resolved by making route.ts which will return user and making fetch call to get in client components. Is it correct?
you can make advantage of ppr where you can have a static shell and dynamic content
other than that, yeah, either via client component or make the whole site dynamic
Dwarf CrocodileOP
What do you mean by PPR?
Pacific sand lance
partial pre-rendering
with similiar use-case i combined ppr with dynamicIO/cacheComponents, then i render something like
<LoginButton/> which internally checks user' session. if user is signed in -> render link to dashboard, otherwise render login button. all this combined with suspense to work with ppr shellDwarf CrocodileOP
Nice 👍 I appreciate
https://nextjs.org/docs/app/getting-started/cache-components#using-suspense-boundaries is this the one I should opt?
https://nextjs.org/docs/app/getting-started/cache-components#using-suspense-boundaries is this the one I should opt?
Pacific sand lance
i mean i use cacheComponents/useCache with ppr as i cache cookies for small period of time
ppr itself would be enough to handle it