Next.js Discord

Discord Forum

How to access client side browser cookies ?

Answered
Black-bellied Whistling-Duck posted this in #help-forum
Open in Discord
Avatar
Black-bellied Whistling-DuckOP
I want to access cookie in client side components.

5 Replies

Avatar
joulev & fuma pray for Schneider
Answer
Avatar
joulev & fuma pray for Schneider
any cookie library will work
Avatar
Black-bellied Whistling-DuckOP
If I use document.cookie method then I get document is not defined error.
Avatar
European sprat
Client components are still pre rendered on the server so you'll need to make sure you check that document exists and/or have it in a useEffect or event handler
Avatar
Black-bellied Whistling-DuckOP
ok