diff --git a/client/src/pages/Question.js b/client/src/pages/Question.js index 3732763..5de6be1 100755 --- a/client/src/pages/Question.js +++ b/client/src/pages/Question.js @@ -4,7 +4,7 @@ import { useState, useEffect } from "react"; import { Link, useParams } from "react-router-dom"; import styled from "styled-components"; import AnswerForm from "../components/AnswerForm"; -// import Pagination from "../components/Pagination"; +import Pagination from "../components/Pagination"; // CSS const QuestionContainer = styled.div` @@ -213,27 +213,27 @@ function Question({ isLogin }) { const [dataA, setDataA] = useState([]); // pagination - // const [posts, setPosts] = useState([]); - // const [currentPage, setCurrentPage] = useState(1); - // const [postsPerPage, setPostPerPage] = useState(5); - - // useEffect(() => { - // const fetchData = async () => { - // const response = await axios.get( - - // ); - // setPosts(response.data) - // }; - // fetchData(); - // }, []); - - // const indexOfLast = currentPage * postsPerPage; - // const indexOfFirst = indexOfLast - postsPerPage; - // const currentPosts = (posts) => { - // let currentPosts = 0; - // currentPosts = posts.slice(indexOfFirst, indexOfLast); - // return currentPosts; - // } + const [posts, setPosts] = useState([]); + const [currentPage, setCurrentPage] = useState(1); + const [postsPerPage, setPostPerPage] = useState(5); + + useEffect(() => { + const fetchData = async () => { + const response = await axios.get( + `${process.env.REACT_APP_API_URL}/api/answers` + ); + setPosts(response.data) + }; + fetchData(); + }, []); + + const indexOfLast = currentPage * postsPerPage; + const indexOfFirst = indexOfLast - postsPerPage; + const currentPosts = (posts) => { + let currentPosts = 0; + currentPosts = posts.slice(indexOfFirst, indexOfLast); + return currentPosts; + } /*단일 질문글 받아오기*/ const getSingleQ = async () => { @@ -386,7 +386,7 @@ function Question({ isLogin }) { {/* 답변 내용 */} {dataA.map((singleA) => ( - +