Next.js Discord

Discord Forum

"use server" and get cookie inside a react component?

Unanswered
Russian Spaniel posted this in #help-forum
Open in Discord
Russian SpanielOP
I'm using Next 13.

I have a use case where I am successfully creating a cookie inside middleware. But my issue is that I need to read this cookie not inside a next page, but in a react component library. I am unable to use state and prop drill. Don't ask why 😄 this is the use case.

I'd like to do something like this:

"use server"

import { cookies } from 'next/headers'

const cookieStore = cookies()
const theme = cookieStore.get('theme')


But I don't know if there is a next page I could install to do this... 🤷‍♂️

I've tried to use the package "cookies-next".

const cookie = getCookie('theme', {
   path: "/"
});


But I get undefined.

Any ideas? 🤔

Thanks

0 Replies