From f200a88855feac8b184a844d04d1e27148a089cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A4=80=ED=9D=AC?= Date: Sun, 25 Feb 2024 23:07:54 +0900 Subject: [PATCH] =?UTF-8?q?FEAT=20:=20=EB=AC=B4=ED=95=9C=EC=8A=A4=ED=81=AC?= =?UTF-8?q?=EB=A1=A4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app.js | 4 +++- src/MainPage/List.tsx | 8 +++----- src/MainPage/Test.tsx | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/app.js b/backend/app.js index d4630663..c3d33226 100644 --- a/backend/app.js +++ b/backend/app.js @@ -27,9 +27,11 @@ async function connectToMongoDB() { connectToMongoDB(); +const PAGE_SIZE = 3; + app.get('/article', async (req, res) => { const pageNumber = req.query.pageNumber ? parseInt(req.query.pageNumber) : 1; - const PAGE_SIZE = 3; + try { const articles = await articleCollection .find({}) diff --git a/src/MainPage/List.tsx b/src/MainPage/List.tsx index 0e95c85d..688aeb7d 100644 --- a/src/MainPage/List.tsx +++ b/src/MainPage/List.tsx @@ -199,7 +199,6 @@ const Post = () => { // 이적 기사 최신순 정렬 console.log(articleData); - console.log('article'); // Intersection Observer를 이용하여 무한 스크롤 감지 const [pageNumber, setPageNumber] = useState(1); @@ -213,13 +212,12 @@ const Post = () => { } }, [inView]); - // axios를 이용하여 데이터를 가져옴 + // 이전 코드와 동일하게 axios를 이용하여 데이터를 가져옴 useEffect(() => { const fetchData = async () => { try { const response = await axios.get(`/article?pageNumber=${pageNumber}`); - const newData = response.data.article.reverse(); - + const newData = response.data.article; setArticleData((prevData) => [...prevData, ...newData]); // 기존 데이터와 새로운 데이터 결합 } catch (error) { console.error('Error fetching user data:', error); @@ -276,7 +274,7 @@ const Post = () => { ) : ( 기사가 없습니다. )} -
+
ㅤㅤㅤ
); diff --git a/src/MainPage/Test.tsx b/src/MainPage/Test.tsx index 18af9776..44b98967 100644 --- a/src/MainPage/Test.tsx +++ b/src/MainPage/Test.tsx @@ -217,7 +217,7 @@ const Post = () => { const fetchData = async () => { try { const response = await axios.get(`/article?pageNumber=${pageNumber}`); - const newData = response.data.articles; + const newData = response.data.article; setArticleData((prevData) => [...prevData, ...newData]); // 기존 데이터와 새로운 데이터 결합 } catch (error) { console.error('Error fetching user data:', error);