import React, { useEffect, useState } from "react"; import { Link } from "react-router-dom"; import { surveyApi } from "../apis"; import { catchErrors } from "../helpers"; import { useSurveys } from "../layouts"; import type { ISurvey } from "../types"; import { SurveyCard } from "./SurveyCard"; export const SurveysList = () => { const [error, setError] = useState(""); const [loading, setLoading] = useState(false); const { surveys, remove: handleDelete } = useSurveys(); // const [surveys, setSurveys] = useState([]); // useEffect(() => { // const getSurveys = async () => { // const surveys: ISurvey[] = await surveyApi.getSurveys(); // // console.log(surveys); // setSurveys(surveys); // }; // getSurveys(); // }, []); /** * 설문 삭제 * @param id survey id */ // const handleDelete = async (id: string) => { // if (window.confirm("해당 설문조사를 삭제하시겠습니까?")) { // try { // setLoading(true); // const result = await surveyApi.deleteSurvey(id); // console.log("deleted survey", result); // setError(""); // const newItems = surveys.filter((survey) => survey._id !== result._id); // // console.log("items left:", newItems); // setSurveys(newItems); // alert("삭제되었습니다."); // } catch (error) { // console.log("에러발생"); // catchErrors(error, setError); // } finally { // setLoading(false); // } // } // }; return (
나의 설문조사
CREATE NEW SURVEY!
{surveys.map((survey) => ( ))}
); };