import React, { useState, MouseEvent, useEffect } from "react"; import { Link } from "react-router-dom"; import { PostType } from "../types"; import Post from "../post/post"; import { postApi } from "../apis"; interface Posts { posts: PostType[]; } export default function BoardPage() { const [posts, setPosts] = useState(); useEffect(() => { getDataList(); }, [posts]); // posts const getDataList = async () => { const res = await postApi.getData(); setPosts(res); }; const titleHandleClick = async (event: MouseEvent) => { const postId = event.currentTarget.id; const newpost = posts?.find((element) => { if (element._id === postId) { return element; } }); if (!(newpost?._id === undefined)) { const post = newpost; const res = await postApi.addCounts(post._id, post.counts); // console.log(res); setPosts(res); } }; return (
자유 게시판
여행지 후기를 남겨주세요!
{" "} {/* Link */}
제목
게시 날짜
조회수
{posts?.map((post, i) => ( ))}
); }