Next.js Discord

Discord Forum

How to populate context in server component?

Unanswered
American Bobtail posted this in #help-forum
Open in Discord
American BobtailOP
I am currently working on migration from pages to app and trying to implement currency selector. Essentially my app should know which currency is selected. Website is internationalized and SSRed (there will be server components eventually) so /en should have USD, /uk should have UAH etc. That is simple enough - fetch default currency from backend by passing down locale to request and let backend decide what's returned. But then I need to make this component interactive, to let users to switch between different currencies without switching to different locale. Now this is hard for me to understand. I'm planning to store state of that component in react context, but how should I populate it in server component? It must fetch data from backend, but then it also should be stateful using context? How to achieve this?

0 Replies