import { useEffect, useState } from "react"; import { useParams, useNavigate } from "react-router-dom"; import { useAppDispatch, useAppSelector } from "../../app/hooks"; import { fetchProductById } from "../../features/catalog/productsSlice"; import styles from "./ProductPage.module.css"; import type { CategoryAtributes, CategoryAtrVals } from "../../types/categories"; const ItemPage = () => { const { id } = useParams(); const dispatch = useAppDispatch(); const navigate = useNavigate(); const { items, loading } = useAppSelector((state) => state.products); const { items: cats, selectedCategoryId } = useAppSelector(s => s.categories); const [activeTab, setActiveTab] = useState<"desc" | "chars">("desc"); useEffect(() => { if (id) dispatch(fetchProductById(id)); }, [id]); const product = items.find((item) => item.id === Number(id)); const category = cats.find((cat) => cat.id === Number(selectedCategoryId)) if ((loading || !product)) return
{product.description}
{product.description}