/react-virtual-infinite-scroll

Let's build: A custom list virtualization and infinite scroll for vertical browsing (TikTok, Youtube Shorts..)

Primary LanguageTypeScript

React Virtual Infinite Scroll Demo

An introduction to how we can do list virtualization from scratch in React.

With this strategy, we will have a scrollable div with three children.

<div className="overflow-y-auto" onScroll={handleUpdateVisibleArea}>
   <!-- Empty div with fixed height -->
  <div style={{ height: countRowsBeforeCurrentIndex * ROW_HEIGHT }} />
  <div>
      <!-- (Visible Area): Render visible row at current index + overscanned rows -->
  </div>
   <!-- Empty div with fixed height -->
  <div style={{ height: countRowsAfterCurrentIndex * ROW_HEIGHT }} />
</div>

Resources used for inspiration

Virtualization strategy illustrated

Virtualization Notes

Run the demo project

Make sure you are using node version ^20 (run node -v).

npm install

Start the development server

npm run dev

This project was bootstrapped using my React Project recipe https://github.com/gullskatten/react-tailwind-vite-ts-base