Click here to Skip to main content
14,735,317 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I tried to do the 'save product to the cart's local storage' functionality by myself, but I had a LOT of trouble implementing it, as you can see in my last question.

So I've reset everything back to what is what before I implemented this, because I really want to know how to properly set this up.

And also, I don't know where to place the local storage function. I originally put it in Products.jsx because the addToCart() function was there, but then I also have my Cart.jsx file, which has the removeFromCart() function there. Unless I create one file dedicated to that, and just call the function in both the files? I'm really clueless...

So my question is: can someone please help / demonstrate how to implement this in my code? I've watched a few tutorials on local storage already, but I'm still puzzled.

Help is very much appreciated,

What I have tried:

I've tried looking at YouTube for tutorials on how to add to cart and then save the product to the cart's local storage in React JS, but all the tutorials I watched didn't show you the Local Storage bit. I also searched this up, but got no solutions...
Updated 17-Nov-20 3:12am
Gerry Schmitz 14-Nov-20 10:05am
"Local storage" is a cookie.
h311o 15-Nov-20 1:39am
@salty06 okay, thanks for the info :)
Richard Deeming 16-Nov-20 3:05am
Gerry Schmitz 16-Nov-20 11:59am
It's 2 mints in one.
h311o 16-Nov-20 20:22pm
So it's not a cookie?
Richard Deeming 17-Nov-20 3:36am
No. Cookies are sent back to the server in a header. Local storage never leaves the browser.
h311o 17-Nov-20 8:09am
@RichardDeeming oh...then what does @salty06 mean about '2 mints in one'?
Richard Deeming 17-Nov-20 9:25am
I'm not sure; you'd have to ask him. :)
h311o 17-Nov-20 22:13pm
Oh, okay. Thanks @RichardDeeming! :D
h311o 20-Nov-20 20:45pm
So does anyone have any solutions on how to do this?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900