Skip to content
Advertisement

Objects not getting stored into localstorage. – React JS

So I’m trying to make a web application which fetches products from backend API and displays it and I’m also trying to implement add to cart functionality which works by storing products added to the cart by the user in their local storage When I click add to cart this is what gets added currently cartItems [{}] which is not what I want. I want to store the actual object of the product. Here is my current code:

JavaScript

Advertisement

Answer

axios.get returns a promise that needs to be resolved via await/then,catch

updated handleClick function:-

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement