skip to Main Content

I created a user state with redux toolkit everything works fine when the user is logged in the userActions sends a request to backend and returns the user info as token and username to display it on the navbar.the problem is the user state is returned to initial state after the page refresh.is it a good idea to use useEffect to send a request to backend after each rerender wich is not a good idea or to use the cash??

i tried to use RTK query to cash the user state but is it secure

2

Answers


  1. That’s a normal behaviour, state is being reset on refresh per specification. If you want to preserve it you need to make use of localStorage/sessionStorage/cookies etc.

    Login or Signup to reply.
  2. That’s where cookies come into play. You can save the user details in cookies for that session. It is good practice to maintain user details in cookies and data in the cookies can be accessed by both client side and the server side.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search