Course contentsShow
← React
Lesson 1280 of 2,39632. Lists and Keys Deep DiveFree lesson

The Virtual Items Array

Understand the virtualizer.getVirtualItems() array: index, start, size, and key properties for positioning.

The Virtual Items Array

You'll learn how the virtualizer.getVirtualItems() array gives you the data needed to position each visible item in your virtualized list.

What the Virtual Items Array Contains

When you call virtualizer.getVirtualItems() from TanStack Virtual's useVirtualizer hook, you get back an array of objects—one for each item that should currently be rendered. These aren't all your items; they're only the ones visible in the viewport (plus a few buffer items for smooth scrolling).

Each object in this array contains the positioning data you need:

  • index — The original index from your full data array
  • start — The absolute position (in pixels) from the top of the virtual container where this item should begin
  • size — The height (or width for horizontal lists) of this item in pixels
  • key — A stable identifier for React's reconciliation

Why These Properties Matter

The start value tells you where to position the item using CSS transforms or absolute positioning. The size determines its dimensions. The index lets you retrieve the actual data from your source array. The key ensures React can track each virtual item correctly across renders.

Think of it like a camera filming a parade: the virtual items array is the "currently in frame" list, with exact coordinates for where each float should appear on screen, even though the parade itself has hundreds of floats.

Key Takeaway: The virtual items array provides index, start, size, and key for each visible item, giving you everything needed to render and position them correctly in your virtualized list.