import React, { useState, MouseEvent, useEffect } from "react"; import { Link, Outlet, useLocation, useNavigate, useOutletContext, } from "react-router-dom"; import { PostType } from "../types"; import Post from "../post/post"; import { postApi } from "../apis"; import { useAuth } from "../auth/auth.context"; interface Props { posts: PostType[]; } interface Newpost { state: PostType; } export default function BoardPage() { const posts = useOutletContext(); const location = useLocation() as Newpost; const newPost = location.state; const navigate = useNavigate(); const { user } = useAuth(); console.log("posts", posts); const handleClick = 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); } }; const GoLogin = async (event: React.MouseEvent) => { if (!user.isLoggedIn) { alert("로그인이 필요합니다."); navigate("/login", { replace: true }); } }; return (
자유 게시판
{/*
여행지 후기를 남겨주세요!
*/}
제목
날짜
조회수
{posts?.map((post, i) => ( ))}
); }