App router with redux-toolkit for SSR not setting to initial state after navigation #60060
Replies: 1 comment
-
I can confirm that the NextJs state is persistent on every user navigation. If you are using To solve this, I add a
Then calling this function to revert the store every time the user navigates
I hope this helps someone having the same concern. Closing discussion. Thank you. |
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
-
I have a simple project using NextJs with the
app
router, and I am also usingredux/redux-toolkit
for state management, but I am having some small issues.When I populate the redux state on "page1", and the user navigates to "page2", the data that has been fetched on "page1" still exists on the redux state even though I did not fetch those data on the "page2". The same thing when the user goes back to "page1" from "page2", the data that I fetch on the "page2" still exists in the redux state.
To give you an idea of what I mean, I created this simple CodeSandbox where you can check.
https://codesandbox.io/p/devbox/nextjs-redux-toolkit-z5x2tw
I am using the
<a>
tag for navigations because the idea is to fetch the data every time the user navigates to a different page. When the user navigates to "Pokemons", we populate thepokemons
state, and when the user navigates to "Pokemon" (without 's'), we only fetch and populate thepokemon
(without 's') state.We are expecting that the redux state should return to the initial state every time the user navigates to a different page since we don't use a persistent state library or save the state to any storage. I believe this should be the default behavior of redux/redux-toolkit, or am I missing something?
Beta Was this translation helpful? Give feedback.
All reactions