How to change context value of Parent page Layout #51301
Unanswered
TristanKirwan
asked this question in
App Router
Replies: 1 comment
-
|
Hello, did you find a solution instead of prop drilling? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone.
Currently I am running into the following issue regarding Server-side components & Context. We have a multilingual project, with several nested routes using the App Router, like so:
In the
layoutof the[lang]route, we render the header, footer and pass along a context provider that provides a glossary object to the children, like so:Inside the
headercomponent, there is another componentLanguageToggle. I would like to pass the correct url for the translated version of the page the user is currently on. For context:/en/newsand/nl/nieuwscould be same page in the CMS and just be translations of the same page. I get this translated url in thepage.tsxof the route the user is on.The problem is that in this route I do not have access to the
/[lang]/layout.tsxfile, where I would like to pass this value via another Context provider. I also do not know the route on which I fetch the required data (for example, it could be on[lang]/[landing_uid]but it could also be on[lang]/[landing_uid]/[detail_uid].Previous I have used Remix, where I could use
useLoaderDataand get the relevant data straight in the component where i need it (<LanguageToggle />), but as far as I can see this is not available. I have also used a getter/setter method in combination with a class, but this doesn't work, as the/[lang]/layout.tsxwould be hit before the actual page where I am doing the fetch call is being hit, meaning I don't have the data when I am setting it to the context provider in/[lang]/layout.tsx. I have also tried to update the context directly on my relevant page (/[lang]/[landing_uid]), but this is not possible on SSC.Has anybody ran into a similar issue that could point me in the right direction?
Beta Was this translation helpful? Give feedback.
All reactions