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.


Related Query

More Query from same tag