Custom Context Provider state reset on routing
Unanswered
Mexican Jay posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
Mexican JayOP
On a new react context, I am trying to isolute the state and have defined the state within a custom provider of the context with copies of the state values and setters placed into the context, however routing in nextjs (Link even with shallow), seems to recreate the custom provider and reset all state to the initial values on each route. I was expecting my context provider to be create (its state set to initial values once)
My provider is similar to that of the academind nextjs course by custom context provider
https://github.com/mschwarzmueller/nextjs-course-code/blob/09-context/store/notification-context.js
Using that as an example, I would expect that the "activeNotification" state variable would keep it's value between route navigations (assuming the timer has not yet triggered)
My provider is similar to that of the academind nextjs course by custom context provider
https://github.com/mschwarzmueller/nextjs-course-code/blob/09-context/store/notification-context.js
Using that as an example, I would expect that the "activeNotification" state variable would keep it's value between route navigations (assuming the timer has not yet triggered)
8 Replies
![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
Mexican JayOP
My NextJS version # is 14.1.0
And adding shallow on the Link does not help.
![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
Mexican JayOP
Using Page Router if that matters.
Can someone confirm if this is a bug? And if yes, how do I report it? (And if no, does NextJS with Page Router (or with another package if needed) have a solution? (Currently I've worked around this by moving the state and setters to the App, but that is really poor design.)
![Avatar](https://cdn.discordapp.com/avatars/606439588810063893/5c5f89b638988ad8de0a93305bc9d5d9.webp?size=256)
cadco_ka
I'm using next-intl.
I don't understand the issue with async. If it's asynchronous, it doesn't work to use translation, which is not allowed. Is there a workaround?
I don't understand the issue with async. If it's asynchronous, it doesn't work to use translation, which is not allowed. Is there a workaround?
![Avatar](https://cdn.discordapp.com/embed/avatars/2.png)
Mexican JayOP
@cadco_ka Your response does not appear to me as connected to my question.
![Avatar](https://cdn.discordapp.com/avatars/606439588810063893/5c5f89b638988ad8de0a93305bc9d5d9.webp?size=256)
cadco_ka
I got it to work now .. missunderstandin in the doc
![Avatar](https://cdn.discordapp.com/avatars/227874586312704000/8b08fc3388d22e2ce6b4fa0b1f60f6ad.webp?size=256)
josh
Could you share the code that uses the
NotificationContextProvider
?