From 713bf024e3da2b2af066e6f119533b4475b0c3a1 Mon Sep 17 00:00:00 2001 From: novice0840 Date: Mon, 25 Sep 2023 21:30:13 +0900 Subject: [PATCH] =?UTF-8?q?useEffect=20Error=20=EB=B0=9C=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/MainPage.tsx | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/frontend/src/pages/MainPage.tsx b/frontend/src/pages/MainPage.tsx index 7aa09ea..4400dae 100644 --- a/frontend/src/pages/MainPage.tsx +++ b/frontend/src/pages/MainPage.tsx @@ -16,7 +16,7 @@ const Main = () => { const lastWebtoonRef = useRef(null); const handleSubmit = () => { - void fetchData(platform); + console.log("subnmit"); }; const handleSearch = (event: React.ChangeEvent) => { @@ -31,24 +31,14 @@ const Main = () => { setDayOfWeeks([...dayOfWeeks, event.target.name as DayOfWeekKind]); }; - const fetchData = async ( - platform = undefined, - dayOfWeeks = undefined, - tags = undefined, - isEnd = undefined - ): Promise => { + const fetchData = async (): Promise => { + const params: { platform?: string } = {}; + if (platform !== "all") params.platform = platform; try { const response = await axios.get<{ info: { totalPage: number; page: number }; data: WebtoonBase[]; - }>(`http://localhost:3001/webtoon/list?page=${page}`, { - params: { - platform, - dayOfWeeks, - tags, - isEnd, - }, - }); + }>(`http://localhost:3001/webtoon/list?page=${page}`, { params }); const data = response.data; setTotalPage(data.info.totalPage); setWebtoons([...webtoons, ...data.data]); @@ -58,11 +48,20 @@ const Main = () => { }; useEffect(() => { + setWebtoons(() => []); + console.log("check1"); + // console.log(webtoons); + // void fetchData(); + }, [platform]); + + useEffect(() => { + console.log("check2"); + void fetchData(); }, [page]); useEffect(() => { - console.log("check"); + console.log("check3"); const observer = new IntersectionObserver((entries, observer) => { if (entries[0].isIntersecting && page <= totalPage) { observer.unobserve(lastWebtoonRef.current as HTMLElement);