79323018

Date: 2025-01-02 07:22:26
Score: 0.5
Natty:
Report link
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.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): why are
  • Low reputation (0.5):
Posted by: Build Though