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

Function Example

examples/react/window/src/main.tsx:8–50  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6import { useWindowVirtualizer } from '@tanstack/react-virtual'
7
8function Example() {
9 const listRef = React.useRef<HTMLDivElement | null>(null)
10
11 const virtualizer = useWindowVirtualizer({
12 count: 10000,
13 estimateSize: () => 35,
14 overscan: 5,
15 scrollMargin: listRef.current?.offsetTop ?? 0,
16 })
17
18 return (
19 <>
20 <div ref={listRef} className="List">
21 <div
22 style={{
23 height: `${virtualizer.getTotalSize()}px`,
24 width: '100%',
25 position: 'relative',
26 }}
27 >
28 {virtualizer.getVirtualItems().map((item) => (
29 <div
30 key={item.key}
31 className={item.index % 2 ? 'ListItemOdd' : 'ListItemEven'}
32 style={{
33 position: 'absolute',
34 top: 0,
35 left: 0,
36 width: '100%',
37 height: `${item.size}px`,
38 transform: `translateY(${
39 item.start - virtualizer.options.scrollMargin
40 }px)`,
41 }}
42 >
43 Row {item.index}
44 </div>
45 ))}
46 </div>
47 </div>
48 </>
49 )
50}
51
52function App() {
53 return (

Callers

nothing calls this directly

Calls 1

useWindowVirtualizerFunction · 0.90

Tested by

no test coverage detected