Windowed List
Render ten thousand rows in a box 400 px tall without putting ten thousand nodes in the DOM.
The starter's WindowedList renders every row of ROWS inside a scrolling viewport. Make it a window instead.
Requirements
- Only the rows that intersect the viewport exist in the DOM, plus a small overscan above and below so fast scrolling doesn't flash blank. The footer's Rendering N of 10000 rows must report the real count.
- The scrollbar reflects the whole list: its range matches
rows.length × rowHeight, and dragging the thumb to the bottom lands on the last row. - Row height is fixed and passed in; what a row looks like comes from
renderRow(row). The component must not know what a row is. - Keys stay stable as the window slides, so a row that stays visible is not remounted.
- Scrolling stays smooth: nothing reads layout during render, and no listener is added per render.
Hints
Hint 1
The only state is scrollTop. The first visible index is floor(scrollTop / rowHeight), the last is ceil((scrollTop + height) / rowHeight). Widen both by the overscan and clamp to the list.
Hint 2
A spacer div as tall as the whole list gives the viewport its scroll range; position each rendered row absolutely at index × rowHeight inside it. One element to size, no top and bottom spacers to keep in sync.
Hint 3
Key by the row's id, not its index in the slice: as the window slides, index 0 is a different row every time.
Sign in to use the assistant — ask what the problem means, get a hint when you're stuck, or have your current work reviewed. Conversations save to your account.