"use client"; import httpClient from "@/request/api"; import { endPoints } from "@/request/links"; import { useQuery } from "@tanstack/react-query"; import { useCategory } from "@/store/useCategory"; import Card from "./card"; import { useTranslations } from "next-intl"; export function MainSubCategory() { const category = useCategory((state) => state.category); const t = useTranslations(); const { data, isLoading, error } = useQuery({ queryKey: ["subCategory"], queryFn: () => httpClient(endPoints.subCategory.byId(category.id)), select: (data) => data?.data?.results, }); if (isLoading) { return (
{[1, 2, 3].map((i) => (
))}
); } if (error) { return (
{t("loading_error")}
); } if (!data || data.length === 0) { return (
{t("products_not_found")}
); } return (
{data.map((item: any) => ( ))}
); }