this is my code.
const fetchCartItem = async () => {
if (token) {const {data } = await axios.get(API.GET_PRODUCT_DETAILS_BY_PRODUCT_ID.replace("[ProductID]",item?.ProductID),{headers:{Authorization: token,},});setCartLoading(false);if (data?.product === undefined) {return {};}else {return data?.product ? data?.product : {};}}};
const{isLoading: itemLoading,refetch: cartRefetch,data: cart,} = useQuery(["cart"], () => fetchCartItem());
CodePudding user response:
If you want to fetch data according to your object ID in useQuery then you just need to pass the ID before calling the function. For ex:
const { isLoading: itemLoading, refetch: cartRefetch, data: cart} = useQuery(["cart", item?.ProductID], () => fetchCartItem());