import { useEffect, useState } from "react";
import { getCartDetail } from "../components/services/_getMethod";
export default function useCartItems() {
const dealer_id = sessionStorage.getItem("dealer_id");
const [items, setItems] = useState([]);
const fetchCartItems = () => {
// getCartDetail() is common api function
getCartDetail("api/ProductDetails/GetCountProductList", dealer_id).then(
(data) => {
// it stores length setItems(data.data.length);
setItems(data.data);
}
);
}
useEffect(() => {
fetchCartItems();
}, [])
return { items, fetchCartItems };
}
why are u storing length in the items? the setItems stores an number to the items state variable and I think somewhere u tried to map this or take this value expecting it to be as array.