Course contentsShow
← React
Lesson 2299 of 2,39650. Performance: Optimization TechniquesFree lesson

Virtualized Grids and Multi-Column Layouts

Extending virtualization to two dimensions with FixedSizeGrid for table-like data and image galleries.

Virtualized Grids and Multi-Column Layouts

You'll learn how to extend virtualization to two dimensions for table-like data and image galleries.

What Are Virtualized Grids?

While FixedSizeList handles vertical scrolling of single-column data, real applications often need grids—think data tables, photo galleries, or calendars. FixedSizeGrid from react-window virtualizes both rows and columns, rendering only the cells visible in the viewport. Instead of tracking just vertical scroll position, it monitors both axes simultaneously.

How FixedSizeGrid Works

Imagine a spreadsheet with 10,000 rows and 50 columns. Without virtualization, React would render 500,000 cells. FixedSizeGrid renders perhaps 20 rows × 10 columns (200 cells), dramatically reducing DOM nodes and render work.

You define:

  • columnCount and rowCount (total dimensions)
  • columnWidth and rowHeight (fixed cell sizes)
  • height and width (viewport size)
  • A Cell component that receives { columnIndex, rowIndex, style }

The grid calculates which cells to render based on scroll position, passing positioning via style.

Typical Use Cases

Data tables: Each cell displays a specific field from row data indexed by rowIndex and columnIndex.

Image galleries: Each cell renders a thumbnail from a two-dimensional array or a flattened list mapped to grid coordinates.

Calendars: Rows are weeks, columns are days—only visible weeks render.

The pattern remains familiar: provide total dimensions, cell sizes, and a render function. The library handles the complex scroll math.

Key Takeaway:
Use FixedSizeGrid to virtualize table-like data across both dimensions, rendering only visible cells for massive performance gains with large two-dimensional datasets.