"use client"; import { useState } from "react"; export function AddToCart({ productId }: { productId: number }) { const [message, setMessage] = useState(""); async function add() { setMessage("Добавляю…"); const response = await fetch("/backend/cart/items", { method: "POST", credentials: "include", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ product_id: productId, qty: 1 }), }); setMessage(response.ok ? "В корзине" : "Не удалось добавить"); } return (
{" "} {message}
); }