Home > Net >  How to keep value in variable between page refreshes?
How to keep value in variable between page refreshes?

Time:04-01

Right now I have a project where I have a input on the landing page, on submit this input calls a another page and I need the value that was in the input to be displayed in the page called, even if page reloads.

I was trying to do this with useContext, but it doesn't work, the page loads correctly, but when I press F5 the value passed down from the input to the second page is erased.

What possible solutions can I use to solve this?

CodePudding user response:

A page reload restart the application from scratch.

There are several options where to store the state you want to keep:

  • SessionSorage
  • LocalStorage
  • Cookies

IMHO, SessionStorage would make the most sense.

Global State libraries like Redux also have plugins to store state persistently.

  • Related