Changed the hardcoded Data on my ecommerce site to fakestore API but now having trouble pushing data
https://github.com/callum-laing/shopping-site
I encountered this issue before but my experience/knowledge with React isn't good enough to figure this out anymore, and I'm at the point where I'd just like to get it working so I can move on to something else 😅
I'm not getting any errors when I try testing lines/functions in the console, you click "add to cart" and it's like nothing happens, literally, so I'm not sure where the missing piece of the puzzle is...
I tried putting this into a codesandbox but it wasn't playing ball, so apologies that i only have my github repo to work with.
6 Replies
To my understanding you have a URL passing some parameters to the cart page, but from the looks of it the cart page isnt looking for that respected data.
Are you trying to do a post request instead?
I did think the cart page was fetching the data, no?
I googled the hell out of this so it coud be a miss-match of various answers that I've maybe missed a tweak somewhere
From your link its passing two queries, id and product
Because from what you posted above it's looking for a local storage object, which I dont think that link would be doing in its process
What you probably want is a post request or a function to add the item to a data object that holds your basket, and then direct the user to the cart page
And on the cart page you just loop through the items in that data, or display an empty cart
That makes sense when I read it, I'd have to figure out how to code that
Its been a few years since ive used react but you can call functions using their version of event handlers
then you could have something like
I can try that, thanks mate, I'll give it a go tomorrow before I sod off for the easter weekend lol