Reading cookies in Client Components during server-rendering with React's use()
hook (Next.js 15)
#79665
Unanswered
anicioalexandre
asked this question in
Help
Replies: 2 comments 1 reply
-
Hey! 👋 Really interesting question — I explored this too. ❗ TL;DR: Using
|
Beta Was this translation helpful? Give feedback.
1 reply
-
@icyJoseph could you advise please? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Context
With Next.js 15,
cookies()
is now async. I need to read cookies in Client Components during their server-side rendering phase. I've implemented this pattern using React'suse()
hook:Then we would just render this component in a server component page.
use()
to handle async cookies in Client Components during SSR considered an anti-pattern?My goal is to have a better UX during reloads and phase rendering transitions. For example, I have a cookie that saves the state of the sidebar menu (collapsed or expanded). During a reload, I want to ensure that it remains in the last state during both server and client renders of a client component.
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions