MCPcopy Index your code
hub / github.com/TanStack/virtual / App

Function App

examples/react/scroll-padding/src/main.tsx:9–99  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7import { useVirtualizer } from '@tanstack/react-virtual'
8
9function App() {
10 const parentRef = React.useRef<HTMLDivElement>(null)
11 const [theadSize, theadRef] = useMeasure<HTMLTableSectionElement>()
12
13 const rowVirtualizer = useVirtualizer({
14 count: 10000,
15 getScrollElement: () => parentRef.current,
16 estimateSize: React.useCallback(() => 35, []),
17 overscan: 5,
18 paddingStart: theadSize?.height ?? 0,
19 scrollPaddingStart: theadSize?.height ?? 0,
20 })
21
22 return (
23 <>
24 <div className="flex gap-2">
25 <button
26 onClick={() => {
27 rowVirtualizer.scrollToIndex(40)
28 }}
29 className="border border-black"
30 >
31 Scroll to index 40
32 </button>
33 <button
34 onClick={() => {
35 rowVirtualizer.scrollToIndex(20)
36 }}
37 className="border border-black"
38 >
39 Then scroll to index 20
40 </button>
41 </div>
42
43 <br />
44 <br />
45
46 <div
47 ref={parentRef}
48 className="List"
49 style={{
50 height: `200px`,
51 width: `400px`,
52 overflow: 'auto',
53 }}
54 >
55 <table
56 style={{
57 height: `${rowVirtualizer.getTotalSize()}px`,
58 width: '100%',
59 }}
60 >
61 <thead ref={theadRef}>
62 <tr>
63 <th>Index</th>
64 <th>Key</th>
65 </tr>
66 </thead>

Callers

nothing calls this directly

Calls 1

useVirtualizerFunction · 0.90

Tested by

no test coverage detected