diff --git a/src/components/common/winelist/WineListCard.tsx b/src/components/common/winelist/WineListCard.tsx index fb89011..f722733 100644 --- a/src/components/common/winelist/WineListCard.tsx +++ b/src/components/common/winelist/WineListCard.tsx @@ -1,7 +1,9 @@ -import { useRef } from 'react'; +import { useEffect, useRef } from 'react'; +import { useQueryClient } from '@tanstack/react-query'; import Link from 'next/link'; +import { getWineInfoForClient } from '@/api/getWineInfo'; import NextIcon from '@/assets/icons/Next.svg'; import StarIcon from '@/assets/icons/star.svg'; import { ImageCard } from '@/components/common/card/ImageCard'; @@ -25,21 +27,38 @@ export default function WineListCard() { threshold: 0.3, }); - if (isLoading) return
불러오는 중...
; - if (isError || !data) return와인 데이터를 불러올 수 없습니다.
; - - const wineList = data.pages.flatMap( + const wineList = data?.pages.flatMap( (page) => (page as GetWinesResponse)?.list?.filter((wine) => !wine.image.includes('example.com')) ?? [], ); + const queryClient = useQueryClient(); + + const prefetchWineInfo = async (wineid: number) => { + await queryClient.prefetchQuery({ + queryKey: ['wineDetail', wineid], + queryFn: () => getWineInfoForClient(wineid), + staleTime: 1000 * 60 * 5, + }); + }; + + // // 데이터 프리패칭용 + useEffect(() => { + wineList?.forEach((wine) => { + prefetchWineInfo(wine.id); + }); + }, [wineList]); + + if (isLoading) return불러오는 중...
; + if (isError || !data) return와인 데이터를 불러올 수 없습니다.
; + return (