Skip to content

Commit

Permalink
Chore: useEffect 합치기
Browse files Browse the repository at this point in the history
  • Loading branch information
irenee-14 committed Sep 9, 2024
1 parent 9919a28 commit 0b8d299
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
2 changes: 1 addition & 1 deletion hooks/agenda/useFetchGet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const useFetchGet = <T>({ url, isReady = true, params }: FetchGetProps) => {
}, [url, isReady, params]);

useEffect(() => {
if (url) {
if (url && isReady) {
getData(); // 조건에 맞을 때만 getData 호출
}
}, [url, isReady, JSON.stringify(params)]);
Expand Down
17 changes: 4 additions & 13 deletions pages/agenda/profile/user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ const AgendaProfile = () => {
const isMyProfile = useRef(false); // 내 프로필 페이지인지 아닌지 확인
const [isIntraId, setIsIntraId] = useState<boolean>(false); // 인트라 아이디가 42에 있는지 확인
const [isAgendaId, setIsAgendaId] = useState<boolean>(false); // 인트라 아이디가 agenda에 있는지 확인
const [agendaProfileData, setAgendaProfileData] =
useState<AgendaProfileDataProps | null>(null); // agendaProfileData 상태 추가

/** API GET */
// GET: intraData (42 인트라 데이터 가져오기)
Expand All @@ -34,7 +32,7 @@ const AgendaProfile = () => {
isReady: Boolean(queryIntraId),
});
// GET: agendaProfileData (GG 아젠다 유저 데이터 가져오기)
const { data: fetchedAgendaProfileData, getData: getAgendaProfileData } =
const { data: agendaProfileData, getData: getAgendaProfileData } =
useFetchGet<AgendaProfileDataProps>({
url: `/profile/${queryIntraId}`,
isReady: isIntraId,
Expand Down Expand Up @@ -78,20 +76,13 @@ const AgendaProfile = () => {
// 2. intraData가 있으면 인트라 아이디가 42에 있다는 뜻이므로 isIntraId = true
setIsIntraId(!!intraData);
// 3. agendaProfileData가 있으면 아젠다에 등록된 사용자이므로 isAgendaId = true
setIsAgendaId(!!fetchedAgendaProfileData);
if (isAgendaId) {
setAgendaProfileData(fetchedAgendaProfileData);
} else {
setAgendaProfileData(null); // fetchedAgendaProfileData가 없을 때 초기화
}
setIsAgendaId(!!agendaProfileData);
};
updateProfileStatus();
}, [queryIntraId, intraData, fetchedAgendaProfileData]);

useEffect(() => {
setIsIntraId(false);
setIsAgendaId(false);
}, [queryIntraId]);
updateProfileStatus();
}, [queryIntraId, intraData, agendaProfileData]);

/** UI Rendering */
if (!queryIntraId || !myIntraId) {
Expand Down

0 comments on commit 0b8d299

Please sign in to comment.