scroll-lite
v0.1.2
Published
A lightweight, dependency-free virtualization component for React. ScrollLite renders only the visible portion of a large list/grid based on the size of the rendered item, providing smooth scrolling and excellent performance — even with thousands of ele
Readme
ScrollLite
A lightweight, dependency-free virtualization component for React.
ScrollLite renders only the visible portion of a large list/grid based on the size of the rendered item, providing smooth scrolling and excellent performance — even with thousands of elements.
Perfect for lists, grids, galleries, product feeds, and any UI where rendering everything at once is too expensive.
🚀 Features
- Ultra-lightweight — no external deps (only React peer dependency)
- Smart virtualization based on item height + scroll offset
- Dynamic margin-top placement for seamless scroll continuity
- Automatic size measurement of the rendered item
- Supports grids & flex layouts
- No need for resize observers or manual height calculations
- Works with any React content
📦 Installation
npm install scroll-lite✨ Usage Example
import { ScrollLite } from "scroll-lite";
function App() {
const items = Array.from({ length: 5000 }, (_, i) => ({
id: i,
title: `Item ${i}`,
}));
return (
<div style={{ height: "600px" }}>
<ScrollLite
elements={items}
renderItem={(item) => (
<div className="p-4 border rounded bg-white shadow">
{item.title}
</div>
)}
/>
</div>
);
}🧠 How It Works
ScrollLite measures the size of a single rendered item.
Based on the scroll position, it calculates:
which items should be visible,
how many extra items to render above/below (buffer),
how large the margin-top should be.
Only those items are rendered into the DOM.
The user can scroll smoothly as if the entire list existed.
This approach reduces memory usage and prevents layout thrashing.
⚙️ Props
elements: T[]
Array of items to display.
renderItem: (item: T, index: number) => ReactNode
Function for rendering a single element.
📏 Automatic Item Measurement
ScrollLite internally measures the height/size of the first rendered item and uses that to compute virtualization.
No config needed.
📄 License
MIT
