[Solved] Objects not getting stored into localstorage. – React JS


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

updated handleClick function:-

    async function handleClick(id) {
     try{
        const chosen_product = await axios.get(`http://localhost:8000/api/products/${id}`)
        const newCart = cart.concat(chosen_product);
        setCart(newCart);
        localStorage.setItem("cartItems", JSON.stringify(newCart));
     }
     catch(error){
      // error-handling goes here
     }
   }

0

solved Objects not getting stored into localstorage. – React JS