Next.js Discord

Discord Forum

What is the best way to share data between server components in Next.js 14 ?

Unanswered
Valentinh posted this in #help-forum
Open in Discord
Hi everyone,

I use Next.js 14 and I retrieve data from a cookie in layout.tsx :

const theme = cookies().get("theme")?.value


I've created a context to share the data in my application's client components and I'd like to know if there's an equivalent for server-side rendering, as I find it redundant to do this in all my server components.

Thank you

2 Replies

Siberian
You can wrap this call in a react cache function so it only runs once per request.