Capítulo 15 de 20
The sticky example keeps the active grouped-list header rendered even when it falls outside the default range. A custom range extractor adds that index, and rendering removes its normal translation.
const rowVirtualizer = useVirtualizer({
count: rows.length,
estimateSize: () => 50,
getScrollElement: () => parentRef.current,
rangeExtractor: React.useCallback(
(range: Range) => {
activeStickyIndexRef.current =
[...stickyIndexes]
.reverse()
.find((index) => range.startIndex >= index) ?? 0
const next = new Set([
activeStickyIndexRef.current,
...defaultRangeExtractor(range),
])
return [...next].sort((a, b) => a - b)
},
[stickyIndexes],
),
})
defaultRangeExtractor(range) and add only the required sticky index.rangeExtractor controls which indexes are returned.