Home > Blockchain >  not losing state when refresh webpage
not losing state when refresh webpage

Time:02-12

I made a Simple WebApp in React.js, that can add food to a cart and see it or finally order it. when I add food, my cart updates and can see data but when I refresh the page, data will be gone how can save data and when I refresh the page still can see it.

CodePudding user response:

You have different solutions to store your data:

  1. LocalStorage with no expiration time
  2. SessionStorage is cleared when the page session ends
  3. Redux is a predictable state container
  4. React Context is designed to share data that can be considered globally for a tree of React components

CodePudding user response:

If you need to save the state of your shopping cart somewhere you can do that server side. You can store it in Session state. When you refresh you refill the page from Session state.

  • Related