Next.js Discord

Discord Forum

cookies()

Answered
Southeastern blueberry bee posted this in #help-forum
Open in Discord
Avatar
Southeastern blueberry beeOP
hey
can i pass cookie value from server component to client component as props ?
Answered by MikeTheTechLead
One little tidbit: Page generation becomes dynamic (as in per request) if you do.
Otherwise, if the cookie is NOT http-only, you can instead grab it out in the client component directly and make sure its only client rendered. This way you can keep the page statically rendered
View full answer

9 Replies

Avatar
hey, yes you can
Avatar
@Southeastern blueberry bee what else do u need?
Avatar
Southeastern blueberry beeOP
Nothing else thanks for your help
Avatar
One little tidbit: Page generation becomes dynamic (as in per request) if you do.
Otherwise, if the cookie is NOT http-only, you can instead grab it out in the client component directly and make sure its only client rendered. This way you can keep the page statically rendered
Answer
Avatar
he can also add export const dynamic = 'force-static' on top of his page and the page will be statically rendered. Btw: that wasnt his question 🙂
Avatar
But then the cookies function will become empty 🙂

What i was getting at was that getting cookies on the server to then pass it to a client component seems a little hacky / wrong to me, and seems to be a way to circumvent a http-only cookie, which is supposed to NOT be accessible in javascript because it can be exploited
But in this case im thinking on stuff like jwt / session cookie or similar
Avatar
Southeastern blueberry beeOP
The cookie is not http-only so I will access it client side instead of passing props down to client thanks for the clarification