Problem
Render a large/endless list efficiently.
Requirements
- Infinite scroll: fetch the next page when the user nears the bottom.
- Virtualization (windowing): only render the rows currently visible (plus a small overscan buffer), not the entire list.
- Maintain correct total scroll height so the scrollbar behaves naturally.
Hints / Approach
- Infinite scroll: use
IntersectionObserveron a sentinel element at the list end, or a scroll listener checkingscrollTop + clientHeight >= scrollHeight - threshold. - Virtualization (fixed row height):
startIndex = floor(scrollTop / rowHeight),visibleCount = ceil(viewportHeight / rowHeight). Render that slice inside a spacer container of heighttotalRows * rowHeight, offset bystartIndex * rowHeight(viatransform: translateYor padding). - Variable heights: maintain measured offsets / use a library approach (binary search over cumulative heights).