import React, { useState, useEffect, useRef } from 'react'; import { Row, Col, Form, Card, Button } from 'react-bootstrap'; function Product() { const [select, setSelect] = useState({ color: "", size: ""}) const [cart, setCart] = useState() function handleClick(e) { const box = e.target.parentNode.parentNode box.style.display = "none" } function handleChange(e) { const { name, value } = e.target setSelect({ ...select, [name]: value }) } function listDelete(e) { e.preventDefault() const parent = e.target.parentNode parent.remove() } function handleCreate() { console.log("실행","cart=",cart) if (cart !== undefined) { if (cart.color !== "") { const list = document.getElementById('list') list.style.borderBottom = "1px solid" const shopping = document.createElement('div') shopping.className = "d-flex justify-content-between my-2" shopping.innerHTML=`${cart.color} / ${cart.size}
14,000원
` const deleteA = document.createElement('a') deleteA.innerText = 'X' deleteA.addEventListener('click', listDelete) shopping.appendChild(deleteA) list.appendChild(shopping) } } } useEffect(() => { if (Object.keys(select).length == 2) { setCart({...select}) setSelect({}) } }, [select]) useEffect(() => { handleCreate() }, [cart]) return (