Skip to content

Conversation

@PocheonLim
Copy link
Collaborator

๐Ÿ“ ๋ฏธ์…˜ ๋ฒˆํ˜ธ

8์ฃผ์ฐจ Misson 1, 2

๐Ÿ“‹ ๊ตฌํ˜„ ์‚ฌํ•ญ

  • Debouncing์„ ์ด์šฉํ•œ ๊ฒ€์ƒ‰ ํ˜ธ์ถœ ์ œํ•œ
  • Throttling์„ ์ด์šฉํ•œ LP ๋ฆฌ์ŠคํŠธ ์ธํ”ผ๋‹ˆํ‹ฐ ์ฟผ๋ฆฌ ๋นˆ๋„ ์ œํ•œ

๐Ÿ“Ž ์Šคํฌ๋ฆฐ์ƒท

bandicam.2025-05-20.01-15-40-878.mp4

โœ… ์ฒดํฌ๋ฆฌ์ŠคํŠธ

  • Merge ํ•˜๋ ค๋Š” ๋ธŒ๋žœ์น˜๊ฐ€ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์„ค์ •๋˜์–ด ์žˆ๋‚˜์š”?
  • ๋กœ์ปฌ์—์„œ ์‹คํ–‰ํ–ˆ์„ ๋•Œ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜์ง€ ์•Š๋‚˜์š”?
  • ๋ถˆํ•„์š”ํ•œ ์ฃผ์„์ด ์ œ๊ฑฐ๋˜์—ˆ๋‚˜์š”?
  • ์ฝ”๋“œ ์Šคํƒ€์ผ์ด ์ผ๊ด€์ ์ธ๊ฐ€์š”?

๐Ÿค” ์งˆ๋ฌธ ์‚ฌํ•ญ

Copy link
Member

@hyesngy hyesngy left a 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๋ฅผ ํฌ๊ฒŒ ํ–ฅ์ƒ์‹œํ‚ค๋Š” ์š”์†Œ์ž…๋‹ˆ๋‹ค. ์•ž์œผ๋กœ ์žˆ์„ ๋ฐ๋ชจ๋ฐ์ด ํ”„๋กœ์ ํŠธ์—์„œ๋„ ๊ผญ ํ™œ์šฉํ•ด์„œ ๊ตฌํ˜„ํ•ด๋ณด๋ฉด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค!๐Ÿ‘๐Ÿป๐Ÿ‘๐Ÿป๐Ÿ‘๐Ÿป

Comment on lines +26 to +50
// fetchNextPage ํ˜ธ์ถœ ์—ฌ๋ถ€๋ฅผ throttle๋œ ๊ฐ’์œผ๋กœ ๊ด€๋ฆฌ
const [shouldFetch, setShouldFetch] = useState(false);
const throttledShouldFetch = useThrottle(shouldFetch, 1000); // 1์ดˆ์— ํ•œ ๋ฒˆ๋งŒ true๋กœ ๋ฐ”๋€œ

useEffect(() => {
if (throttledShouldFetch) {
fetchNextPage();
setShouldFetch(false);
}
}, [throttledShouldFetch, fetchNextPage]);

useEffect(() => {
const handleScroll = () => {
if (
window.innerHeight + window.scrollY >= document.documentElement.scrollHeight - 100 &&
hasNextPage &&
!isFetchingNextPage
) {
setShouldFetch(true);
}
};

window.addEventListener('scroll', handleScroll);
return () => window.removeEventListener('scroll', handleScroll);
}, [hasNextPage, isFetchingNextPage]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํ˜„์žฌ LpListPage์—์„œ๋Š” ์ง์ ‘ ์Šคํฌ๋กค ์ด๋ฒคํŠธ๋ฅผ ๊ด€๋ฆฌํ•˜๊ณ  ์žˆ๋Š”๋ฐ, ์ด๋ฏธ ๊ตฌํ˜„๋œ useInfiniteScrollํ›…์„ ํ™œ์šฉํ•˜์ง€ ์•Š๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ์ปดํฌ๋„ŒํŠธ๋ฅผ ํ™œ์šฉํ•˜๋ฉด ์ฝ”๋“œ ์ค‘๋ณต์„ ์ค„์ด๊ณ  ์œ ์ง€๋ณด์ˆ˜๊ฐ€ ์šฉ์ดํ•ด์ง‘๋‹ˆ๋‹ค. useInfiniteScrollํ›…์„ ์‚ฌ์šฉํ•˜์—ฌ ์Šคํฌ๋กค ๋กœ์ง์„ ๋ถ„๋ฆฌํ•˜๋ฉด ์ฝ”๋“œ์˜ ๊ฐ€๋…์„ฑ์ด ํ–ฅ์ƒ๋˜๊ณ  ์ปดํฌ๋„ŒํŠธ์˜ ์ฑ…์ž„์„ ๋ช…ํ™•ํžˆ ํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์•„์š”!

Comment on lines +26 to +35
// fetchNextPage ํ˜ธ์ถœ ์—ฌ๋ถ€๋ฅผ throttle๋œ ๊ฐ’์œผ๋กœ ๊ด€๋ฆฌ
const [shouldFetch, setShouldFetch] = useState(false);
const throttledShouldFetch = useThrottle(shouldFetch, 1000); // 1์ดˆ์— ํ•œ ๋ฒˆ๋งŒ true๋กœ ๋ฐ”๋€œ

useEffect(() => {
if (throttledShouldFetch) {
fetchNextPage();
setShouldFetch(false);
}
}, [throttledShouldFetch, fetchNextPage]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํ˜„์žฌ throttle์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•ด shouldFetch ์ƒํƒœ์™€ throttledShouldFetch๋ฅผ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š”๋ฐ, ์Šคํฌ๋กค ์ด๋ฒคํŠธ์—์„œ ๋ฐ”๋กœ throttle๋œ ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ๋ณ€๊ฒฝํ•˜๋ฉด ์ƒํƒœ ๊ด€๋ฆฌ๊ฐ€ ์ค„์–ด๋“ค์–ด ์ฝ”๋“œ๊ฐ€ ๋” ๊ฐ„๊ฒฐํ•ด์ง€๊ณ  ์ดํ•ดํ•˜๊ธฐ ์‰ฌ์›Œ์ง‘๋‹ˆ๋‹ค. ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ์— ์ง์ ‘ throttle์„ ์ ์šฉํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ๊ฐœ์„ ํ•ด๋ณด๋ฉด ์–ด๋–จ๊นŒ์š”?

@PocheonLim PocheonLim merged commit a049ced into main May 26, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants