Capítulo 14 de 20
This example virtualizes table rows below a measured table header. paddingStart accounts for the header in total geometry, while scrollPaddingStart keeps imperative targets clear of it.
const [theadSize, theadRef] = useMeasure<HTMLTableSectionElement>()
const rowVirtualizer = useVirtualizer({
count: 10000,
getScrollElement: () => parentRef.current,
estimateSize: React.useCallback(() => 35, []),
overscan: 5,
paddingStart: theadSize?.height ?? 0,
scrollPaddingStart: theadSize?.height ?? 0,
})
<button onClick={() => rowVirtualizer.scrollToIndex(40)}>
Scroll to index 40
</button>