fix(WEB): 모바일 인피니티 스크롤 중복 key 에러 수정
- 데이터 누적 시 getItemId로 중복 항목 필터링 - 페이지 전환 시 동일 데이터 중복 추가 방지 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -300,15 +300,19 @@ export function IntegratedListTemplateV2<T = any>({
|
||||
setAccumulatedMobileData(data);
|
||||
setLastAccumulatedPage(1);
|
||||
} else if (pagination.currentPage === lastAccumulatedPage + 1) {
|
||||
// 다음 페이지: 기존 데이터에 누적
|
||||
setAccumulatedMobileData(prev => [...prev, ...data]);
|
||||
// 다음 페이지: 기존 데이터에 누적 (중복 제거)
|
||||
setAccumulatedMobileData(prev => {
|
||||
const existingIds = new Set(prev.map(item => getItemId(item)));
|
||||
const newItems = data.filter(item => !existingIds.has(getItemId(item)));
|
||||
return [...prev, ...newItems];
|
||||
});
|
||||
setLastAccumulatedPage(pagination.currentPage);
|
||||
} else if (pagination.currentPage !== lastAccumulatedPage) {
|
||||
// 페이지 점프 (예: PC에서 페이지 변경 후 모바일로): 현재 데이터만 표시
|
||||
setAccumulatedMobileData(data);
|
||||
setLastAccumulatedPage(pagination.currentPage);
|
||||
}
|
||||
}, [data, pagination.currentPage, pagination.totalItems, allData, enableMobileInfinityScroll, lastAccumulatedPage]);
|
||||
}, [data, pagination.currentPage, pagination.totalItems, allData, enableMobileInfinityScroll, lastAccumulatedPage, getItemId]);
|
||||
|
||||
// 탭 변경 감지: activeTab 변경 시 누적 데이터 리셋
|
||||
// 주의: allData를 dependency에 넣으면 페이지 변경 시마다 리셋됨 (외부 훅 사용 시)
|
||||
|
||||
Reference in New Issue
Block a user