Next.js Discord

Discord Forum

using context with next server components

Unanswered
Oak Titmouse posted this in #help-forum
Open in Discord
Oak TitmouseOP
I have a particular use case in which i need to fetch data on the server in my root layout and i need that throughout my app. The question is first how do i set that data in state or context to be used throughout the app and second how do i utilize the state by keeping most of my components server side.

6 Replies

Hi, I've written some content about that
Basically, "cache" can be used as a server equivalent to React client context
The cache function is scoped to the current request => you can put data that belong only to the current user there, and reuse it in all the components that are server rendered for the current page (= current HTTP request)