배포 다시..

This commit is contained in:
leeheejin
2026-01-19 09:50:25 +09:00
parent 58adc0a100
commit 8603fddbcb
3 changed files with 44 additions and 30 deletions

View File

@@ -51,14 +51,18 @@ export function useVirtualScroll(options: VirtualScrollOptions): VirtualScrollRe
// 보이는 아이템 수
const visibleCount = Math.ceil(containerHeight / itemHeight);
// 시작/끝 인덱스 계산
// 시작/끝 인덱스 계산 (음수 방지)
const { startIndex, endIndex } = useMemo(() => {
// itemCount가 0이면 빈 배열
if (itemCount === 0) {
return { startIndex: 0, endIndex: -1 };
}
const start = Math.max(0, Math.floor(scrollTop / itemHeight) - overscan);
const end = Math.min(
itemCount - 1,
Math.ceil((scrollTop + containerHeight) / itemHeight) + overscan
);
return { startIndex: start, endIndex: end };
return { startIndex: start, endIndex: Math.max(start, end) }; // end가 start보다 작지 않도록
}, [scrollTop, itemHeight, containerHeight, itemCount, overscan]);
// 전체 높이