useContext for Server Components
Unanswered
Willow Flycatcher posted this in #help-forum
Willow FlycatcherOP
Is there some way to setup useContext with app directory/server components or is there an equivalent for it?
4 Replies
no, but there are fundamentally equivalent options to share the same data across Server Components. if you are fetching some data for example, you can fetch it twice in both components and Next will dedupe the requests
@Rafael Almeida no, but there are fundamentally equivalent options to share the same data across Server Components. if you are fetching some data for example, you can fetch it twice in both components and Next will dedupe the requests
Willow FlycatcherOP
Im currently generating a random value in my layout.tsx which I need to be able to acccess in all other components. Whats the best way to do this?
unfortunately as far as i know layout.tsx and page.tsx files are evaluated in parallel so i'm afraid what you are trying to do might be impossible
you can use server-only-context if you want to consume that random value in a component imported to that layout.tsx, but a component in a different layout.tsx or page.tsx file likely can't access that random value