import React, { useEffect, useMemo, useState } from "react"; import DataIteration from "../Helpers/DataIteration"; import AvailableJobsCard from "../Cards/AvailableJobsCard"; export default function MainSection({ className, marketPlaceProduct, categories, }) { // Creating All cart.. let marketCategories = useMemo( () => ({ All: "All Categories", ...categories }), [categories] ); const [tab, setTab] = useState(marketCategories.All); // Convert to array in order to map const mappedArray = Object.entries(marketCategories).map(([key, value]) => { return { key, value }; }); const [products, setProducts] = useState([]); const tabHandler = (value) => { setTab(value); }; useEffect(() => { if (tab === marketCategories.All) { setProducts(marketPlaceProduct); } else { const filteredProducts = marketPlaceProduct.filter((product) => product.category.includes(tab) ); setProducts(filteredProducts); } }, [tab, marketPlaceProduct, categories, marketCategories]); return (
{mappedArray.map(({ key, value }) => ( tabHandler(key)} className={`md:text-[18px] text-md text-dark-gray dark:text-white hover:text-pink border-b hover:border-pink font-medium cursor-pointer ${ tab === key ? "text-pink border-pink" : " border-transparent" }`} > {value} ))}
{({ datas }) => ( )}
); }