import React, { useState, useEffect, useRef } from 'react'; import MainNav from '../Components/MainNav'; import SubNav from '../Components/SubNav'; import { Row, Col, Button, Form, Container, Alert } from 'react-bootstrap'; import axios from 'axios'; import catchErrors from "../utils/catchErrors"; function ProductsRegist() { const [product, setProduct] = useState() const [error, setError] = useState('') function handleChange(e) { const { name, value, files } = e.target if (files) { setProduct({ ...product, [name]: files }) } else { setProduct({ ...product, [name]: value }) } } async function handleSubmit(e) { e.preventDefault() const formData = new FormData(); for (const key in product) { console.log("product[key]=", product[key]) if (key == "main_image" || key == "detail_image") { for (const file of product[key]) { formData.append(key, file) } } else { formData.append(key, product[key]) } } // formData 값 확인용 // for (const key of formData.keys()) { // console.log("key=",key); // } // for (const value of formData.values()) { // console.log(value); // } try { const response = await axios.post('/api/product/regist', formData) } catch (error) { catchErrors(error, setError) } } return (
{console.log(product)} {error && {error}}

상품등록

상품명 재고 가격 분류 상품설명 대표이미지 상세이미지
) } export default ProductsRegist