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
Black-bellied Whistling-DuckOP
I want to access cookie in client side components.

5 Replies

Answer
any cookie library will work
Black-bellied Whistling-DuckOP
If I use document.cookie method then I get document is not defined error.
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
Black-bellied Whistling-DuckOP
ok