Skip to content

Commit 3a7e546

Browse files
authored
Merge pull request #82 from CodeItBoost3/bug/group
그룹 목록 불필요한 요청 수정
2 parents 1decc6c + 77f64c7 commit 3a7e546

File tree

2 files changed

+25
-28
lines changed

2 files changed

+25
-28
lines changed

src/pages/Group.jsx

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useEffect } from "react";
1+
import { useState, useEffect, useCallback } from "react";
22
import { useToast } from "@/hooks/useToast";
33
import { useSearchParams, useNavigate } from "react-router-dom";
44
import { IoRefresh } from "react-icons/io5";
@@ -65,34 +65,33 @@ export default function Group() {
6565
fetchUserInfo();
6666
}, []);
6767

68-
useEffect(() => {
69-
if (isSearching) return;
70-
71-
const fetchGroupList = async () => {
72-
try {
73-
const response = await groupService.getGroupList({
74-
type: isPublic ? "public" : "private",
75-
sortBy,
76-
keyword: "",
77-
page: currentPage,
78-
});
79-
80-
if (response.status === "success") {
81-
setGroupData(response.data.groups || []);
82-
setTotalPages(response.data.totalPage);
83-
} else {
84-
throw new Error("그룹 목록 조회 실패");
85-
}
86-
} catch {
87-
if(isLogin) addToast("그룹 목록 조회에 실패했습니다.");
68+
const fetchGroupList = useCallback(async () => {
69+
if (isSearching) return; // 검색 중이면 요청하지 않음
70+
71+
try {
72+
const response = await groupService.getGroupList({
73+
type: isPublic ? "public" : "private",
74+
sortBy,
75+
keyword: "",
76+
page: currentPage,
77+
});
78+
79+
if (response.status === "success") {
80+
setGroupData(response.data.groups || []);
81+
setTotalPages(response.data.totalPage);
8882
}
89-
};
90-
83+
} catch {
84+
addToast("그룹 목록 조회에 실패했습니다.");
85+
}
86+
}, [isPublic, sortBy, currentPage, isSearching, addToast]);
87+
88+
useEffect(() => {
9189
fetchGroupList();
92-
}, [isPublic, sortBy, currentPage, isSearching, groupData]);
90+
}, [fetchGroupList]);
91+
9392

9493
useEffect(() => {
95-
setSortBy(searchParams.get("sortBy") || "mostLiked");
94+
setSortBy(searchParams.get("sortBy") || "latest");
9695
}, [searchParams]);
9796

9897
const handleLoginModal = (type) => {

src/pages/MemoryPost.jsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export default function MemoryPost() {
3333
const [post, setPost] = useState(null);
3434
const [comments] = useState("");
3535

36-
// ✅ 게시글 상세 정보 가져오기 (useCallback 적용)
3736
const fetchPostDetail = useCallback(async () => {
3837
if (!postId) return;
3938
try {
@@ -50,7 +49,6 @@ useEffect(() => {
5049
fetchPostDetail();
5150
}, [fetchPostDetail]);
5251

53-
// ✅ 스크랩 상태 조회 (useCallback 적용)
5452
const fetchScrapStatus = useCallback(async () => {
5553
if (!postId) return;
5654
try {
@@ -179,7 +177,7 @@ useEffect(() => {
179177
}
180178

181179
return (
182-
<div className="w-full max-w-[900px] mx-auto pt-6 pb-10">
180+
<div className="w-full max-w-[90%] mx-auto pt-6 pb-10">
183181
<div className="flex justify-between items-start">
184182
<div>
185183
<div className="flex items-center text-sm space-x-2">

0 commit comments

Comments
 (0)