Socket
Book a DemoInstallSign in
Socket

inferno-virtual-list

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

inferno-virtual-list

Virtual List that only renders visible items. Supports millions of rows. Recycles efficiently via Inferno JS.

latest
Source
npmnpm
Version
0.2.0
Version published
Maintainers
1
Created
Source

inferno-virtual-list NPM

A "virtual" list that only renders visible items. Supports millions of rows. Recycles efficiently via Inferno JS.

This is a simple component that allows you to create very long, scrollable lists that perform extremely fast. It allows a configurable buffer zone to render items above and below the visible viewport bounds.

Demo

preview

Install

You must also include inferno and inferno-component.

NPM

$ npm install --save inferno-virtual-list inferno inferno-component

CDN

<script src="https://unpkg.com/inferno@1.0.7/dist/inferno.min.js"></script>
<script src="https://unpkg.com/inferno@1.0.7/dist/inferno-component.min.js"></script>
<script src="https://unpkg.com/inferno-virtual-list@0.1.0/dist/inferno-virtual-list.min.js"></script>

Usage

Provide the List of items as data, an item renderer as rowRender, and the height of a single row as rowHeight. Everything else is optional.

Note: If installed via CDN, the component is exposed as VirtualList. Otherwise, you may call it whatever you'd like!

import List from 'inferno-virtual-list';

const Item = row => (
  <div class="item">{ row }</div>
)

<List
  sync
  buffer={ 10 }
  rowHeight={ 22 }
  rowRender={ Item }
  data={ ['a', 'b', 'c'] }
/>

Props

data

Type: Array
Default: []
List of data items

sync

Type: Boolean
Default: false
If truthy, forces synchronous rendering.

It's best to try without sync enabled first. You should only enable sync if you experience flickering. Doing so ensures every update is applies to the DOM before continuing, but does this at the cost of framerate.

buffer

Type: Number
Default: 10
The number of extra rows to render above & below the visible list.

rowHeight

Type: Number
Default: none
The static height of a row (in pixels). Do not include units!

rowRender

Type: Function
Default: none
The renderer function for each list item.

id

Type: String
Default: none
The id attribute to pass down.

className

Type: String
Default: none
The className attribute to pass down.

Examples

const DIV = document.getElementById('container');
const DATA = [];
// Generate 100,000 rows of data
for (let x=1e5; x--; ) DATA[x] = `Item #${x+1}`;

Functional

View this example on JSFiddle

import Inferno from 'inferno';
import List from 'inferno-virtual-list';

// renders a single row
const Row = row => (
  <div className="row">{row}</div>
);

Inferno.render((
  <List className="list" data={DATA} rowHeight={30} rowRender={Row} />
), DIV);

Stateful

View this example on JSFiddle

import Inferno from 'inferno';
import Component from 'inferno-component';
import List from 'inferno-virtual-list';

class Demo extends Component {
  // 30px tall rows
  rowHeight = 30;

  // Renders a single row
  renderItem(row) {
    return <div className="row">{row}</div>;
  }

  render() {
    return (
      <List sync
        data={DATA}
        className="list"
        rowHeight={this.rowHeight}
        rowRender={this.renderItem}
      />
    );
  }
}

Inferno.render(<Demo />, DIV);

Credit

:tophat: Major hat tip to @_developit and his work on preact-virtual-list, from which this module was ported.

License

MIT © Luke Edwards

FAQs

Package last updated on 06 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts