React context is reset after page change #54821
Replies: 8 comments 1 reply
-
|
@Crismon96 , I have this working in one app by wrapping {children} in the RootLayout: And in providers.jsx: This is working fine in one app, but with another where I am not fetching data in layout.js, but rather in a nested dynamic page I am running into problems. It seems that we cannot wrap nested pages individually in context providers and retain context state throughout the app. I've tried passing in an empty array to the providers in RootLayout, but route changes reset context instead of maintain current state. I would love to have some insight on how others are dealing with this. |
Beta Was this translation helpful? Give feedback.
-
Yeah, I have the same problem |
Beta Was this translation helpful? Give feedback.
-
|
I am also having similar issues, It kinda defeats the point of using context to begin with. |
Beta Was this translation helpful? Give feedback.
-
|
I ran into this as well while trying stop Ended up converting my context over to a zustand hook... works as expected with changes persisting across navigation. |
Beta Was this translation helpful? Give feedback.
-
|
@Crismon96 You've marked this as resolved, why? |
Beta Was this translation helpful? Give feedback.
-
|
I'm also still having this issue |
Beta Was this translation helpful? Give feedback.
-
|
I think this issue is not resolved yet. My solution was using Link from |
Beta Was this translation helpful? Give feedback.
-
|
I’m experiencing a similar issue. The strange thing is that everything works perfectly in the local environment, but in the production environment, the context value resets whenever I navigate between pages. What’s even more puzzling is that, after retrying a few times, it eventually starts working as expected. I’m curious if anyone else has faced a similar problem. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a context that should span multiple pages. When reading the migration guide I have moved my contexts into a client component:
This wrapper is used in my Root Layout:
My NavigationBar which is also in my custom ContextWrapper does the basic navigation:
When I move pages my context is always reset but my context is in a client component in the RootLayout. This is how it should be done, right? It is not my logic that resets the Context, it is unmounted.
Can one of you provide a best practice solution to have app wide state with react context across multiple pages?
Beta Was this translation helpful? Give feedback.
All reactions