CharlesStover/reactn

Global state resets after Route change

Selyatin opened this issue · 5 comments

I have a login page and I'm receieving user data then setting the global state according to the user data, then I forward the user to the main page where he should be able to view his data via the global state, but the state is being turned back to it's default state.

example

login route "/user/login"

main page "/"

user logs in via login route then goes to main page and the state resets to default values

Are you using React router or a single page application? The global state is only stored in memory. It is not persisted across page reloads.

There are some extensions that persist it, if you are not working on a single page app.

Are you using React router or a single page application? The global state is only stored in memory. It is not persisted across page reloads.

There are some extensions that persist it, if you are not working on a single page app.

I'm using React Router. I will search for those extensions, but in case you reply faster than I can search I would appreciate if you recommended one! Thank you.

If you are using React router, then redirecting to a different page should not cause your application to unmount. Can you share the code you are using to redirect from one page to another? It seems as if you are not using React router's built in methods for redirecting, which is causing your application to unmount and lose its global state.

If you are using React router, then redirecting to a different page should not cause your application to unmount. Can you share the code you are using to redirect from one page to another? It seems as if you are not using React router's built in methods for redirecting, which is causing your application to unmount and lose its global state.

Yes that was the exact issue and I fixed it, but now I'm having issues with some buttons, the client tried to convert their base html, js and css project onto a React project without making the necessary changes, so I'm dealing with that right now...

I'm sorry to hear that. I'm glad you resolved your original issue. I'm going to go ahead and close this ticket since it's not actionable on my half. Best of luck with the rest of the conversion process. 🙂