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

Function RowVirtualizerDynamic

examples/react/padding/src/main.tsx:42–93  ·  view source on GitHub ↗
({ rows }: { rows: Array<number> })

Source from the content-addressed store, hash-verified

40}
41
42function RowVirtualizerDynamic({ rows }: { rows: Array<number> }) {
43 const parentRef = React.useRef<HTMLDivElement>(null)
44
45 const rowVirtualizer = useVirtualizer({
46 count: rows.length,
47 getScrollElement: () => parentRef.current,
48 estimateSize: () => 50,
49 paddingStart: 100,
50 paddingEnd: 100,
51 })
52
53 return (
54 <>
55 <div
56 ref={parentRef}
57 className="List"
58 style={{
59 height: `200px`,
60 width: `400px`,
61 overflow: 'auto',
62 }}
63 >
64 <div
65 style={{
66 height: `${rowVirtualizer.getTotalSize()}px`,
67 width: '100%',
68 position: 'relative',
69 }}
70 >
71 {rowVirtualizer.getVirtualItems().map((virtualRow) => (
72 <div
73 key={virtualRow.key}
74 data-index={virtualRow.index}
75 ref={rowVirtualizer.measureElement}
76 className={virtualRow.index % 2 ? 'ListItemOdd' : 'ListItemEven'}
77 style={{
78 position: 'absolute',
79 top: 0,
80 left: 0,
81 width: '100%',
82 height: `${rows[virtualRow.index]}px`,
83 transform: `translateY(${virtualRow.start}px)`,
84 }}
85 >
86 Row {virtualRow.index}
87 </div>
88 ))}
89 </div>
90 </div>
91 </>
92 )
93}
94
95function ColumnVirtualizerDynamic({ columns }: { columns: Array<number> }) {
96 const parentRef = React.useRef<HTMLDivElement>(null)

Callers

nothing calls this directly

Calls 1

useVirtualizerFunction · 0.90

Tested by

no test coverage detected