score:4
Accepted answer
maintain the state in localstorage
. you could stringify the entire json and store it an item called cart
const cartobj = {
item1: {},
item2: {},
}
localstorage.setitem("cart", json.stringify(cartobj));
// getting back the object
const copycartobj = json.parse(localstorage.getitem("cart"));
note: if you use sessionstorage
it will get destroyed once you close the tab. so you requirement is as such you use it otherwise go with localstorage
.
hope this helps. any doubts ping me in the comments.
Source: stackoverflow.com
Related Query
- Add Items to cart without the user logged in react.js and redux
- React router briefly shows the login screen and then redirects to dashboard if user is logged in
- How to add a legend to the map using react leaflet, without using refs and manually modifying the DOM?
- On button click check the checkbox and add the data into cart in react redux?
- Add user input data to show in a table using react js and redux
- React and Redux Shopping cart, add to cart action
- How can I add a new item and render it without the timeout? React
- not able to add items to cart from product page using react redux
- Is there anyway to authenticate the user type(user and Supplier) without any token in react and go with different page when I fetch the response api?
- How we can maintain the state of logged in and loggedout users and share that state to homepage in react redux
- How to programmatically add a className and a onLoad function to all the images in the project at once in React app without Jqyery
- How to link react with redux to add and remove selected movies to the array by clicking on the heart to display them on the favoŠ³ites page
- The cart does not update in real time react and redux
- How to add Items to an existing array without affecting the current ones in React
- How to display the last page when user clicks on add new row,so that user can view the newly added row using react js and prime react
- How can I make my React Component mount, when the right url is accessed and the user is not logged in?
- Can I send an AJAX call in React and Redux without action creators and reducers?
- How i can limit the items in the FlatList and add load more?
- What is the correct way to change Navbar values in React based on if user is logged in?
- Connecting a component with OwnProps using react redux and typescript in the .NET Core 2.0 reactredux template project
- How to tell if a user is logged in with http only cookies and JWT in react (client-side)
- How to add login authentication and session to ReactJS React Router and Redux with MongoDB + NodeJS Express?
- How can I cache data that I already requested and access it from the store using React and Redux Toolkit
- How to use currying to create HoC in React and connect to the Redux store at the same time?
- React vs Redux props on the 'constructor' and 'super'
- How to add page transitions to React without using the router?
- In React and Material-UI how do I make my Grid items take up 100% of available horizontal space w/o wrapping to the next row?
- Add class on focus change using Redux and React
- React Redux - storing logged in user details
- How to add type FunctionComponent to React functional component using the "function" syntax and not "const"?
More Query from same tag
- How can I make multiple styling for only one prop in React Styled Components?
- Reuse component used in different context in react
- Material UI TextField Custom Attribute
- The "x-auth-token" header in Router.all() returns undefined
- What's the redux-react way to manipulate props in react children component
- Display each item in array on new line
- 2 function calls into onChange - ReactJS
- react component is passing down the default value of useState instead of passing the API data
- Recharts CustomTooltip loses background opacity
- Detect handle change inside componentDidUpdate method - Reactjs
- How can I reload a URL with a new query parameter with NextJS?
- Connect multiple redux sub-states to a React component
- OnSubmit in React
- How to Bind "this" with setState callback
- How to style react styled components using classNames
- Why does my child component render multiple times?
- How do I update my API data using form input data?
- react hooks with redux, state not updating
- (React and Django) Displaying products on the homepage is working fine, but when I click on any particular product, then the rendering is wrong
- Passing props in React-TypeScript
- onMouseEnter and onMouseLeave to animate multiple Lottie icons in React
- Why changes from local state don't go into global state?
- Why is removing an item from a list with the key as index working as expected?
- External Vendor Scripts( JS, Jquery) Not working after render in ReactJS
- React: cant get output inside a functional component
- Typescript error because of props in conditional rendering
- Routes/Redirects do not render in a React Router 4 & Redux Authorization
- Destructuring this.props into Component
- How to display image which was uploaded by Multer when query data with Mongoose
- Get data value of array object using Swapi