I have a demo here
It's a cart with products that can be added to a cart and show a total.
I'm using context for the state as the products and cart are different components.
I'd like to use localstorage to storage the cart and total data so if the page is refreshed the cart data won't be lost.
I can store the data in the localstorage with
useEffect(() => {
localStorage.setItem("cart", JSON.stringify(items));
total();
}, [items]);
but I'm not sure how to use this when the page loads again.
I want a cart where I can add and delete products and have them stored in local storage, I'm not sure if using context is the best option or it might be better just using localstorge.
But anyway how can I use localstorage to load the cart and total data when the page is refreshed.