import React, { FormEvent, useEffect, useState } from "react"; import { mainimgApi } from "../apis"; import { catchErrors } from "../helpers"; import { MainimgType } from "../types"; export default function Admin() { const [getimgs, setGetimgs] = useState([]); async function imgsData() { const imgs = await mainimgApi.getmainimg(); console.log("ㅑㅡㅎ", imgs) setGetimgs(imgs) }; useEffect(() => { imgsData(); }, []); const [addimg, setAddimg] = useState({ theme: "", city: "", url: "", title: "", }); const [loading, setLoading] = useState(false); const [error, setError] = useState(""); const [success, setSuccess] = useState(false); function handleSelectChange(event: React.ChangeEvent) { const { name, value } = event.currentTarget; setAddimg({ ...addimg, [name]: value }); } function handleInputeChange(event: React.ChangeEvent) { const { name, value } = event.currentTarget; setAddimg({ ...addimg, [name]: value }); } console.log("asdafsdfs", getimgs) async function handleSubmit(event: FormEvent) { event.preventDefault(); try { setError(""); console.log("img data", addimg); setLoading(true); const res = await mainimgApi.mainimg(addimg); console.log("서버연결됬나요", res); setSuccess(true); setError(""); } catch (error) { console.log("에러발생"); catchErrors(error, setError); } finally { setLoading(false); } } if (success) { alert("img 추가되었습니다"); } return (

url

{/* type="file"/> */}

title

{getimgs.map((img, index: number) => (
) )}
); };