Skip to content

Commit db8375e

Browse files
committed
fix: refetch 에러 시 정적 폴백 전환 방지
1 parent aa57fad commit db8375e

File tree

1 file changed

+12
-13
lines changed
  • frontend/src/pages/MainPage/components/Banner

1 file changed

+12
-13
lines changed

frontend/src/pages/MainPage/components/Banner/Banner.tsx

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ const Banner = () => {
2020
const [swiperInstance, setSwiperInstance] = useState<SwiperType | null>(null);
2121
const [currentIndex, setCurrentIndex] = useState(0);
2222
const bannerType = isMobile ? 'WEB_MOBILE' : 'WEB';
23-
const {
24-
data: banners,
25-
isLoading,
26-
isFetched,
27-
isError,
28-
} = useGetBanners(bannerType);
23+
const { data: banners, isLoading, isFetched } = useGetBanners(bannerType);
2924

3025
const fallbackBanners = BANNERS.map((banner) => ({
3126
id: banner.id,
@@ -34,9 +29,13 @@ const Banner = () => {
3429
alt: banner.alt,
3530
}));
3631

37-
const shouldUseFallback =
38-
isFetched && (isError || (banners?.length ?? 0) === 0);
39-
const displayBanners = shouldUseFallback ? fallbackBanners : (banners ?? []);
32+
const hasApiBanners = (banners?.length ?? 0) > 0;
33+
const shouldUseFallback = isFetched && !hasApiBanners;
34+
const displayBanners = hasApiBanners
35+
? banners
36+
: shouldUseFallback
37+
? fallbackBanners
38+
: [];
4039

4140
const handlePrev = () => {
4241
swiperInstance?.slidePrev();
@@ -76,7 +75,7 @@ const Banner = () => {
7675
return null;
7776
}
7877

79-
if (displayBanners.length === 0) {
78+
if (displayBanners?.length === 0) {
8079
return null;
8180
}
8281

@@ -103,7 +102,7 @@ const Banner = () => {
103102
}}
104103
speed={500}
105104
>
106-
{displayBanners.map((banner) => (
105+
{displayBanners?.map((banner) => (
107106
<SwiperSlide key={banner.id}>
108107
<Styled.BannerItem
109108
isClickable={!!banner.linkTo}
@@ -122,13 +121,13 @@ const Banner = () => {
122121
</Swiper>
123122
{isMobile && (
124123
<Styled.NumericPagination>
125-
{currentIndex + 1} / {displayBanners.length}
124+
{currentIndex + 1} / {displayBanners?.length ?? 0}
126125
</Styled.NumericPagination>
127126
)}
128127

129128
{!isMobile && (
130129
<Styled.DotPagination>
131-
{displayBanners.map((_, index) => (
130+
{displayBanners?.map((_, index) => (
132131
<Styled.Dot key={index} active={currentIndex === index} />
133132
))}
134133
</Styled.DotPagination>

0 commit comments

Comments
 (0)