Cookies in client side
Unanswered
Blood cockle posted this in #help-forum
Blood cockleOP
How to get cookies in client side anyone have idea
11 Replies
https://nextjs.org/docs/app/api-reference/functions/cookies
Get it from a server component and pass it as props
Get it from a server component and pass it as props
Or use any JavaScript libraries to get cookie from the browser you can find
This for example https://github.com/js-cookie/js-cookie
@joulev This for example https://github.com/js-cookie/js-cookie
Blood cockleOP
didn't work for me
@Blood cockle didn't work for me
how did you use it?
@joulev how did you use it?
Blood cockleOP
npm i js-cookie then import this Cookie from package then use like this Cookies.get('name')
in Navbar Component
Cookies.set("name","value") also not worked
you have to use it inside a
if you use it like this it doesn't work
because the component is prerendered on the server
if you don't want to use
useEffect or an event handlerif you use it like this it doesn't work
function Component() {
const name = Cookie.get("name");
return <div>{name}</div>;
}because the component is prerendered on the server
if you don't want to use
useEffect or event handlers you need to use headers() in a server component and pass as propAmerican black bear
You can also create a route hanlder o use a server action