-
Notifications
You must be signed in to change notification settings - Fork 0
Create Week8 Mission1, 2 #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
hyesngy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ΄λ² μ£Ό μν¬λΆμ ν΅ν΄ Reactμ μ±λ₯ μ΅μ ν κΈ°λ²μΈ debounceμ throttleμ μ μ©ν΄λ΄€μ΅λλ€! μ½μ§ μμ κ°λ
μ΄μ§λ§ λͺ¨λ μ ν΄λ΄μ
μ λλ¨ν©λλ€! ππ»ππ»ππ»
μ΄λ° μ΅μ ν κΈ°λ²λ€μ μ€μ μλΉμ€μμ UXλ₯Ό ν¬κ² ν₯μμν€λ μμμ λλ€. μμΌλ‘ μμ λ°λͺ¨λ°μ΄ νλ‘μ νΈμμλ κΌ νμ©ν΄μ ꡬνν΄λ³΄λ©΄ μ’κ² μ΅λλ€!ππ»ππ»ππ»
| <div className="flex justify-end mb-6"> | ||
| <div className="bg-gray-800 rounded-lg p-1 inline-flex"> | ||
| <button | ||
| className={`px-4 py-2 rounded-md transition-all ${ | ||
| order === 'desc' | ||
| ? 'bg-pink-600 text-white' | ||
| : 'bg-transparent text-gray-300 hover:text-white' | ||
| }`} | ||
| onClick={() => setOrder('desc')} | ||
| > | ||
| μ΅μ μ | ||
| </button> | ||
| <button | ||
| className={`px-4 py-2 rounded-md transition-all ${ | ||
| order === 'asc' | ||
| ? 'bg-pink-600 text-white' | ||
| : 'bg-transparent text-gray-300 hover:text-white' | ||
| }`} | ||
| onClick={() => setOrder('asc')} | ||
| > | ||
| μ€λλμ | ||
| </button> | ||
| </div> | ||
| </div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
νμ¬ search-pageμ home-pageμμ μ λ ¬ λ²νΌ UIκ° μ€λ³΅λκ³ μλλ°, μ΄ λΆλΆμ λ³λμ SortButton μ»΄ν¬λνΈλ‘ λΆλ¦¬νλ©΄ μ½λ μ€λ³΅μ μ€μ΄κ³ μΌκ΄λ UIλ₯Ό μ μ§ν μ μμ κ² κ°μ΅λλ€.
| <LpCard key={lp.id} lp={lp} /> | ||
| ))} | ||
|
|
||
| {!isLoading && <LpCardSkeletonList count={20} />} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
νμ¬ home-pageμμ μ€μΌλ ν€μ λ‘λ© μ€μ΄ μλ λλ νμ νμνλλ‘ κ΅¬νλμ΄μλλ°, μλλ λμμΈμ§ μ΄ν΄κ° κ°μ§ μμ΅λλ€. μΆκ° λ°μ΄ν°λ₯Ό λΆλ¬μ¬ λμλ§, μ€μΌλ ν€μ 보μ¬μ£Όλ κ²μ΄ μ¬μ©μμκ²λ λͺ νν νΌλλ°±μ μ λ¬ν μ μμ κ² κ°μ΅λλ€.
μΌλ°μ μΌλ‘ isFetchingNextPage μνμ λ°λΌ 쑰건λΆλ‘ λ λλ§νμ¬ μμλ‘λ {isFetchingNextPage && <LpCardSkeletonList count={20} />} μ΄λ° μμΌλ‘ μμ±ν μ μμ κ² κ°μ΅λλ€.
| const [search, setSearch] = useState(''); | ||
| const [order, setOrder] = useState<'desc' | 'asc'>('desc'); | ||
| const debouncedSearch = useDebounce(search, 500); | ||
| const { ref, inView } = useInView({ threshold: 0 }); | ||
| const throttledInView = useThrottle(inView, 1000); | ||
|
|
||
| const { data, fetchNextPage, hasNextPage, isFetchingNextPage, isLoading } = | ||
| useGetInfiniteLpList(10, order, debouncedSearch); | ||
|
|
||
| useEffect(() => { | ||
| if (throttledInView && hasNextPage && !isFetchingNextPage) { | ||
| fetchNextPage(); | ||
| console.log('λ€μ νμ΄μ§ νΈμΆ'); | ||
| } | ||
| }, [throttledInView, hasNextPage, isFetchingNextPage, fetchNextPage]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2025-05-22.220636.mp4
νμ¬ λ¬΄ν μ€ν¬λ‘€μμ μ¬λ¬ λ²μ μμ²μ΄ μ°μμΌλ‘ λ°μνλ λ¬Έμ κ° μμ΅λλ€.
home-pageμ search-page λͺ¨λμμ useEffect(() => { if (throttledInView && hasNextPage && !isFetchingNextPage) { fetchNextPage(); } }, [throttledInView, hasNextPage, isFetchingNextPage, fetchNextPage])λ‘ κ΅¬νλμ΄ μλλ°, fetchNextPage() μ€ν ν hasNextPageκ° μ¬μ ν trueμ΄κ³ throttledInViewλ κ³μ trueλ‘ μ μ§λλ©΄μ μ°μμ μΌλ‘ μμ²μ΄ λ°μνκ³ μλ κ² κ°μ΅λλ€.
λν, useInView({ threshold: 0 })λ‘ μ€μ λμ΄ μμ΄μ νκ² μμκ° νλ©΄μ μ‘°κΈμ΄λΌλ 보μ΄λ©΄ μ¦μ νΈλ¦¬κ±°λ©λλ€. λν <div ref={ref} className="h-10 mt-4"></div> μμκ° κ³μ νλ©΄μ λ
ΈμΆλμ΄ μμ΄μ μ§μμ μΌλ‘ inViewκ° true μνλ₯Ό μ μ§νκ² λ©λλ€.
fetchNextPage() νΈμΆ μ§ν throttledInViewλ₯Ό μΌμμ μΌλ‘ falseλ‘ λ§λ€κ±°λ, μμ² μλ£ νμλ§ λ€μ κ°μ§ν μ μλλ‘ μν κ΄λ¦¬λ₯Ό κ°μ ν΄μΌ ν©λλ€. useCallbackμΌλ‘ fetchNextPage ν¨μλ₯Ό κ°μΈμ λΆνμν μμ‘΄μ± λ³κ²½μ λ°©μ§νλ κ²λ κ³ λ €ν΄λ³Ό μ μμ κ² κ°μ΅λλ€.
Intersection Observerμμλ thresholdλ₯Ό 0.1 μ λλ‘ λμ΄κ±°λ, rootMarginμ μμκ°μΌλ‘ μ€μ νμ¬ μμκ° μμ ν νλ©΄ μ€μμ λ€μ΄μμ λλ§ νΈλ¦¬κ±°λλλ‘ μ‘°μ νμ¬ μ νν μμ μλ§ κ°μ§λλλ‘ κ°μ ν΄μ£ΌμΈμ!
|
|
||
| const SearchPage: React.FC = () => { | ||
| const [search, setSearch] = useState(''); | ||
| const [order, setOrder] = useState<'desc' | 'asc'>('desc'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
νμ¬ HomePageμμ νλμ½λ©λ "asc" | "desc" νμ
μ μ¬μ©νκ³ μμ΅λλ€. PAGINATION_ORDER enumμ λ³λ νμΌμ μ μν΄λ¨μμλ λΆκ΅¬νκ³ λ¬Έμμ΄ λ¦¬ν°λ΄ νμ
μ μ§μ μ¬μ©νλ©΄ νμ
μ μκ° μ€λ³΅λκ³ μ μ§λ³΄μμ±λ λ¨μ΄μ§λλ€.
μ μν΄λ enumμ μ¬μ©ν΄μ useState<PAGINATION_ORDER>(PAGINATION_ORDER.DESC) κ°μ ννλ‘ λ³κ²½νλ©΄, νμ
μμ μ±μ λμ΄κ³ μ½λ μ μ§λ³΄μμ±λ κ°μ ν μ μμ κ² κ°μ΅λλ€!
π λ―Έμ λ²νΈ
8μ£Όμ°¨ Misson 1, 2
π ꡬν μ¬ν
π μ€ν¬λ¦°μ·
β 체ν¬λ¦¬μ€νΈ