import axios from 'axios'; import React, { useState, useEffect, useRef } from 'react'; import { Row, Col, Form, Card, Button } from 'react-bootstrap'; import catchErrors from '../utils/catchErrors'; const INIT_PRODUCT = { pro_name: '스키니진', price: 12000, count:1, main_category: 'PANTS', sub_category: ['SKINNY JEANS'], sizes: [ 'L', 'M'], colors: ['연청', '진청'], main_image: "a8f4d63ead77717f940a2b27deb707a6" } function Product() { const [product, setProduct] = useState(INIT_PRODUCT) const [cart, setCart] = useState(INIT_PRODUCT) const [error, setError] = useState('') function handleClick(e) { const box = e.target.parentNode.parentNode box.style.display = "none" } function handleChange(e) { const { name, value } = e.target // handleCreate() setCart({ ...cart, [name]: value }) } function listDelete(e) { e.preventDefault() const parent = e.target.parentNode parent.remove() } function handleCreate() { console.log("실행", "cart=", product) if (product !== undefined) { if (product.colors !== "" && product.sizes !== "") { cart.push(
{product.color} {product.size}
{product.price}
14,000원
` // const deleteA = document.createElement('a') // deleteA.innerText = 'X' // deleteA.addEventListener('click', listDelete) // shopping.appendChild(deleteA) // list.appendChild(shopping) } } } async function addCart() { // color, size, count, productId(productlist에서 props), userId(로컬) 를 보내줌 try { // setError('') const response = await axios.put('/api/cart/addcart', { count: cart.count, productId: "5ffd153b41bada58d8b12d92", }) console.log(response) } catch (error) { catchErrors(error, setError) } } // useEffect(() => { // handleCreate() // }, [product]) return (