Next.js Discord

Discord Forum

How to make one component use cookie while still get static rendering.

Unanswered
Dwarf Crocodile posted this in #help-forum
Open in Discord
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?

8 Replies

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 shell
Dwarf CrocodileOP
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