Skip to content

Commit

Permalink
postCardList에 스크롤 복원 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
BumgeunSong committed Jan 2, 2025
1 parent 311d88f commit e807d3d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/components/pages/board/PostCardList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import StatusMessage from '../../common/StatusMessage';
import { usePosts } from '@/hooks/usePosts';
import { useInView } from 'react-intersection-observer';
import PostCardSkeleton from '@/components/ui/PostCardSkeleton';

import { useScrollRestoration } from '@/hooks/useScrollRestoration';
interface PostCardListProps {
boardId: string;
onPostClick: (postId: string) => void;
Expand All @@ -26,11 +26,15 @@ const PostCardList: React.FC<PostCardListProps> = ({ boardId, onPostClick, selec

const allPosts = postPages?.pages.flatMap((page) => page) || [];

const { saveScrollPosition, restoreScrollPosition } = useScrollRestoration(`${boardId}-posts`);

const handlePostClick = (postId: string) => {
onPostClick(postId);
saveScrollPosition();
};

useEffect(() => {
restoreScrollPosition();
if (inView && hasNextPage) {
fetchNextPage();
}
Expand Down

0 comments on commit e807d3d

Please sign in to comment.