All Projects → clauderic → React Tiny Virtual List

clauderic / React Tiny Virtual List

Licence: mit
A tiny but mighty 3kb list virtualization library, with zero dependencies 💪 Supports variable heights/widths, sticky items, scrolling to index, and more!

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Tiny Virtual List

react-functional-select
Micro-sized & micro-optimized select component for React.js
Stars: ✭ 165 (-91.98%)
Mutual labels:  virtualization, windowing
react-bolivianite-grid
React grid component for virtualized rendering large tabular data.
Stars: ✭ 95 (-95.38%)
Mutual labels:  react-component, virtualization
react-recycled-scrolling
Simulate normal scrolling by using only fixed number of DOM elements for large lists of items with React Hooks
Stars: ✭ 26 (-98.74%)
Mutual labels:  react-component, virtualization
react-layer-stack
Layering system for React. Useful for popover/modals/tooltip/dnd application
Stars: ✭ 158 (-92.32%)
Mutual labels:  react-component, windowing
aurelia-virtual-scroll
Aurelia Virtual Scroller
Stars: ✭ 15 (-99.27%)
Mutual labels:  virtualization, windowing
vue-virtual-scroll-grid
A Vue 3 component that can render a list with 1000+ items as a grid in a performant way.
Stars: ✭ 64 (-96.89%)
Mutual labels:  windowing, virtual-scroll
React Virtualized
React components for efficiently rendering large lists and tabular data
Stars: ✭ 22,963 (+1016.33%)
Mutual labels:  virtualization, windowing
React Page Progress
🎉 Sweet Component powered by React Hooks 🚀 👉
Stars: ✭ 148 (-92.81%)
Mutual labels:  react-component
React Useragent
Integrate user-agent detection in an idiomatic React way
Stars: ✭ 154 (-92.51%)
Mutual labels:  react-component
React Border Wrapper
A wrapper for placing elements along div borders.
Stars: ✭ 147 (-92.85%)
Mutual labels:  react-component
Appvm
Nix-based app VMs
Stars: ✭ 146 (-92.9%)
Mutual labels:  virtualization
React Plaid Link
React bindings for Plaid Link
Stars: ✭ 148 (-92.81%)
Mutual labels:  react-component
Slim
Build and run tiny vms from Dockerfiles. Small and sleek.
Stars: ✭ 1,902 (-7.54%)
Mutual labels:  virtualization
Core
Eru, a simple, stateless, flexible, production-ready orchestrator designed to easily integrate into existing workflows. Can run any virtualization things in long or short time.
Stars: ✭ 147 (-92.85%)
Mutual labels:  virtualization
Window Table
Windowing Table for React based on React Window
Stars: ✭ 160 (-92.22%)
Mutual labels:  virtualization
React User Tour
Give your user a guided tour around your application
Stars: ✭ 146 (-92.9%)
Mutual labels:  react-component
Material Ui Datatables
An another React Data tables component.
Stars: ✭ 163 (-92.08%)
Mutual labels:  react-component
Vga Passthrough
Up to date (2021) reference for setting up a VGA passthrough on (Ubuntu) Linux.
Stars: ✭ 157 (-92.37%)
Mutual labels:  virtualization
React Ds
🔥 React Drag To Select component (tiny, touch friendly, and no dependencies!)
Stars: ✭ 153 (-92.56%)
Mutual labels:  react-component
Ion Phaser
A web component to use Phaser Framework with Angular, React, Vue, etc 🎮
Stars: ✭ 152 (-92.61%)
Mutual labels:  react-component

react-tiny-virtual-list

A tiny but mighty list virtualization library, with zero dependencies 💪

npm version npm downloads Build Status codecov typescript license Gitter

  • Tiny & dependency free – Only 3kb gzipped
  • Render millions of items, without breaking a sweat
  • Scroll to index or set the initial scroll offset
  • Supports fixed or variable heights/widths
  • Vertical or Horizontal lists

Check out the demo for some examples, or take it for a test drive right away in Code Sandbox.

Getting Started

Using npm:

npm install react-tiny-virtual-list --save

ES6, CommonJS, and UMD builds are available with each distribution. For example:

import VirtualList from 'react-tiny-virtual-list';

You can also use a global-friendly UMD build:

<script src="react-tiny-virtual-list/umd/react-tiny-virtual-list.js"></script>
<script>
var VirtualList = window.VirtualList;
...
</script>

Example usage

import React from 'react';
import {render} from 'react-dom';
import VirtualList from 'react-tiny-virtual-list';

const data = ['A', 'B', 'C', 'D', 'E', 'F', ...];

render(
  <VirtualList
    width='100%'
    height={600}
    itemCount={data.length}
    itemSize={50} // Also supports variable heights (array or function getter)
    renderItem={({index, style}) =>
      <div key={index} style={style}> // The style property contains the item's absolute position
        Letter: {data[index]}, Row: #{index}
      </div>
    }
  />,
  document.getElementById('root')
);

Prop Types

Property Type Required? Description
width Number | String* Width of List. This property will determine the number of rendered items when scrollDirection is 'horizontal'.
height Number | String* Height of List. This property will determine the number of rendered items when scrollDirection is 'vertical'.
itemCount Number The number of items you want to render
renderItem Function Responsible for rendering an item given it's index: ({index: number, style: Object}): React.PropTypes.node. The returned element must handle key and style.
itemSize Either a fixed height/width (depending on the scrollDirection), an array containing the heights of all the items in your list, or a function that returns the height of an item given its index: (index: number): number
scrollDirection String Whether the list should scroll vertically or horizontally. One of 'vertical' (default) or 'horizontal'.
scrollOffset Number Can be used to control the scroll offset; Also useful for setting an initial scroll offset
scrollToIndex Number Item index to scroll to (by forcefully scrolling if necessary) x
scrollToAlignment String Used in combination with scrollToIndex, this prop controls the alignment of the scrolled to item. One of: 'start', 'center', 'end' or 'auto'. Use 'start' to always align items to the top of the container and 'end' to align them bottom. Use 'center' to align them in the middle of the container. 'auto' scrolls the least amount possible to ensure that the specified scrollToIndex item is fully visible.
stickyIndices Number[] An array of indexes (eg. [0, 10, 25, 30]) to make certain items in the list sticky (position: sticky)
overscanCount Number Number of extra buffer items to render above/below the visible items. Tweaking this can help reduce scroll flickering on certain browsers/devices.
estimatedItemSize Number Used to estimate the total size of the list before all of its items have actually been measured. The estimated total height is progressively adjusted as items are rendered.
onItemsRendered Function Callback invoked with information about the slice of rows/columns that were just rendered. It has the following signature: ({startIndex: number, stopIndex: number}).
onScroll Function Callback invoked whenever the scroll offset changes within the inner scrollable region. It has the following signature: (scrollTop: number, event: React.UIEvent<HTMLDivElement>).

* Width may only be a string when scrollDirection is 'vertical'. Similarly, Height may only be a string if scrollDirection is 'horizontal'

Public Methods

recomputeSizes (index: number)

This method force recomputes the item sizes after the specified index (these are normally cached).

VirtualList has no way of knowing when its underlying data has changed, since it only receives a itemSize property. If the itemSize is a number, this isn't an issue, as it can compare before and after values and automatically call recomputeSizes internally. However, if you're passing a function to itemSize, that type of comparison is error prone. In that event, you'll need to call recomputeSizes manually to inform the VirtualList that the size of its items has changed.

Common Issues with PureComponent

react-tiny-virtual-list uses PureComponent, so it only updates when it's props change. Therefore, if only the order of your data changes (eg ['a','b','c'] => ['d','e','f']), react-tiny-virtual-list has no way to know your data has changed and that it needs to re-render.

You can force it to re-render by calling forceUpdate on it or by passing it an extra prop that will change every time your data changes.

Reporting Issues

Found an issue? Please report it along with any relevant details to reproduce it. If you can, please provide a live demo replicating the issue you're describing. You can fork this Code Sandbox as a starting point.

Contributions

Feature requests / pull requests are welcome, though please take a moment to make sure your contributions fits within the scope of the project. Learn how to contribute

Acknowledgments

This library draws inspiration from react-virtualized, and is meant as a bare-minimum replacement for the List component. If you're looking for a tiny, lightweight and dependency-free list virtualization library that supports variable heights, you're in the right place! If you're looking for something that supports more use-cases, I highly encourage you to check out react-virtualized instead, it's a fantastic library ❤️

License

react-tiny-virtual-list is available under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].