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:
- LocalStorage with no expiration time
- SessionStorage is cleared when the page session ends
- Redux is a predictable state container
- 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.