Skip to content

Comments

Create Week8 Mission1, 2#104

Merged
PocheonLim merged 1 commit intomainfrom
pocheonLim
May 26, 2025
Merged

Create Week8 Mission1, 2#104
PocheonLim merged 1 commit intomainfrom
pocheonLim

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의 성능 최적화 기법인 debouncethrottle을 적용해봤습니다! 쉽지 않은 개념이지만 모두 잘 해내셔서 대단합니다! 👏🏻👏🏻👏🏻

이런 최적화 기법들은 실제 서비스에서 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.

2 participants