1
1
'use client' ;
2
2
3
3
import { useSearchParams } from 'next/navigation' ;
4
- import { useEffect , useState } from 'react' ;
4
+ import { useEffect , useState , Suspense } from 'react' ;
5
5
import { categories } from '@/entities/category' ;
6
6
import type { CategoryItem } from '@/entities/category/type' ;
7
7
import { Header } from '@/shared/ui' ;
@@ -73,7 +73,6 @@ const CategoryPage = () => {
73
73
const categoryName = searchParams . get ( 'view' ) ;
74
74
75
75
const [ selectedCategory , setSelectedCategory ] = useState < number | null > ( null ) ;
76
- const [ isLoading , setIsLoading ] = useState ( true ) ;
77
76
78
77
const currentCategory = categoryName
79
78
? categories . find ( category => category . name === categoryName )
@@ -97,7 +96,6 @@ const CategoryPage = () => {
97
96
if ( currentCategory ) {
98
97
setSelectedCategory ( 0 ) ;
99
98
}
100
- setTimeout ( ( ) => setIsLoading ( false ) , 1000 ) ; // 로딩 시뮬레이션
101
99
} , [ currentCategory ] ) ;
102
100
103
101
const filteredProducts =
@@ -154,11 +152,15 @@ const CategoryPage = () => {
154
152
className = 'grid justify-center gap-[20px]'
155
153
style = { { gridTemplateColumns : 'repeat(auto-fit, 160px)' } }
156
154
>
157
- { isLoading ? (
158
- < Typography size = 'h5' className = 'text-gray-500' >
159
- 로딩 중...
160
- </ Typography >
161
- ) : filteredProducts . length > 0 ? (
155
+ < Suspense
156
+ fallback = {
157
+ < Typography size = 'h5' className = 'text-gray-500' >
158
+ 로딩 중...
159
+ </ Typography >
160
+ }
161
+ > </ Suspense >
162
+ { /*filteredProducts 배열이 비어 있지 않은 경우*/ }
163
+ { filteredProducts . length > 0 &&
162
164
filteredProducts . map ( product => (
163
165
< RaffleCard
164
166
key = { product . id }
@@ -169,8 +171,9 @@ const CategoryPage = () => {
169
171
isBookmarked = { product . isBookmarked }
170
172
hashtags = { product . hashtags }
171
173
/>
172
- ) )
173
- ) : (
174
+ ) ) }
175
+ { /*filteredProducts 배열이 비어 있는 경우*/ }
176
+ { filteredProducts . length === 0 && (
174
177
< Typography size = 'h5' className = 'text-gray-500' >
175
178
상품 추가 예정입니다.
176
179
</ Typography >
0 commit comments