Virtual list
Render only the visible slice of a long list, using fixed-height windowing and an absolute spacer.
- #react
- #components
- #performance
- #virtualization
Renders a window of rows around the scroll position and reserves the rest of the height with a spacer. The number of DOM nodes stays the same whatever the dataset size.
Overview
Ten thousand rows cost tens of thousands of DOM nodes, which stalls layout and holds memory. Windowing renders the two dozen rows on screen.
Implementation
Variable row heights
Fixed heights keep the arithmetic to one multiplication. Variable heights need row measurement and a cumulative offset index, which is far more code. Reach for a library before writing that by hand.
Accessibility
Windowing hides the count of rows from assistive technology. Set aria-setsize to the full length and aria-posinset to the absolute index on each row.
Related entries
- Headless data table. Supplies the row model this list renders.
- List virtualization budget. The measurements that decide whether this component is worth it.
Related entries
List virtualization budget
Decide when windowing is worth its complexity, using node counts and a measured frame budget.
useIntersectionObserver hook
Track element visibility for lazy loading, infinite scroll and scroll-spy navigation.
SVG Particles
Turn an SVG path into a canvas particle field by painting it once, reading the pixels back, and animating the dots under the cursor.