Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/hooks/photoFeed/posts/useInfinitePosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ export function useInfinitePosts() {
getNextPageParam: (lastPage, allPages) =>
lastPage.previewList.length < PAGE_SIZE ? undefined : allPages.length,

staleTime: 1000 * 60 * 5, // 5분 동안은 "신선" → 마운트돼도 refetch 안 함
gcTime: 1000 * 60 * 30, // 30분간 캐시 유지 (v5, v4면 cacheTime)
staleTime: 1000 * 60, // 1분 동안은 "신선" → 마운트돼도 refetch 안 함
gcTime: 1000 * 60 * 5, // 5분간 캐시 유지
Comment on lines +20 to +21
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

가독성을 위해 시간 값을 상수로 정의하는 것이 좋습니다. 예를 들어, const MINUTE_IN_MS = 60 * 1000; 와 같이 상수를 정의하고 staleTime: MINUTE_IN_MS, gcTime: 5 * MINUTE_IN_MS 처럼 사용하면 코드를 이해하기 더 쉬워집니다. 이 파일 내에서 지역 상수로 정의하거나, 여러 곳에서 사용된다면 공통 constants 파일로 분리하는 것을 고려해 보세요.

refetchOnMount: false, // 컴포넌트 마운트 시 재요청 막기
refetchOnWindowFocus: false, // 탭 다시 클릭/포커스 시 재요청 막기
refetchOnReconnect: false, // 네트워크 재연결 시 재요청 막기
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SHOULD: 이제 봤지만 refetchOnReconnect 정도는 살려둬도 괜찮을거 같아요!

retry: 1, // (선택) 실패 시 재시도 횟수 줄이기
retry: 1, // 실패 시 재시도 횟수 줄이기
});
}
15 changes: 12 additions & 3 deletions src/pages/photoFeed/PhotoFeedPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ const breakpointColumnsObj = {
1024: 2,
};

export const TOAST_FADE_START_DELAY = 1600;
export const TOAST_UNMOUNT_DELAY = 3000;

export default function PhotoFeedPage() {
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
const sentinelRef = useRef<HTMLDivElement | null>(null);
Expand All @@ -41,14 +44,20 @@ export default function PhotoFeedPage() {
useEffect(() => {
if (!isDeleted) return;

const fadeTimer = setTimeout(() => setToastVisible(false), 1600);
const removeTimer = setTimeout(() => setMounted(false), 3000);
const fadeTimer = setTimeout(
() => setToastVisible(false),
TOAST_FADE_START_DELAY,
);
const removeTimer = setTimeout(() => {
setMounted(false);
navigate(location.pathname, { replace: true }); // 타이머 없앨 때 state도 같이 삭제
}, TOAST_UNMOUNT_DELAY);

return () => {
clearTimeout(fadeTimer);
clearTimeout(removeTimer);
};
}, [isDeleted]);
}, [isDeleted, navigate, location.pathname]);

const {
data,
Expand Down
11 changes: 9 additions & 2 deletions src/pages/photoFeed/PostPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import EmptyView from "@/components/common/EmptyView";
import CommentSheet from "@/components/photoFeed/postDetail/CommentSheet";
import { useNewPostState } from "@/store/useNewPostState.store";
import ProfileSkeleton from "@/components/photoFeed/postDetail/ProfileSkeleton";
import { TOAST_FADE_START_DELAY, TOAST_UNMOUNT_DELAY } from "./PhotoFeedPage";

export default function PostPage() {
const [commentVisible, setCommentVisible] = useState(false);
Expand Down Expand Up @@ -63,8 +64,14 @@ export default function PostPage() {
useEffect(() => {
if (!isNewPost) return;

const fadeTimer = setTimeout(() => setToastVisible(false), 1600);
const removeTimer = setTimeout(() => setMounted(false), 3000);
const fadeTimer = setTimeout(
() => setToastVisible(false),
TOAST_FADE_START_DELAY,
);
const removeTimer = setTimeout(() => {
setIsNewPost(false);
setMounted(false);
}, TOAST_UNMOUNT_DELAY);

return () => {
clearTimeout(fadeTimer);
Expand Down