npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-virtual-scrolling

v1.1.4

Published

This react component allows you to use virtualization for a very long list of data.

Downloads

29

Readme

react-virtual-scrolling

This react component allows you to use virtualization for a very long list of data.

It provides smooth performance experience while scrolling the list.

Why Virtual Scrolling

Reason why this component is created:

Problem Statement -

Have you ever come across a situation where you have a large list of data and 10000 or 20000 rows need to be rendered on DOM. DOM can't handle such a large data and performance while scrolling or loading the screen gets a serious hit. Sometimes, DOM also breakdown.

Solution -

We should render only the rows that are visible in the viewport, all others should get rendered only when they come into visibility. Otherwise they should not get rendered at all. This keeps our DOM light and have only necessary information.

Benefits -

Thus, for the above solution, react-virtual-scrolling is created. It's key benefits are-

  • Fast performance ( if earlier, list rendering was taking 6s, now it takes some milliseconds only ).
  • Better control on DOM
  • Any number of rows can be rendered, no limit on the number of rows.

Installation

To install this Component, run yarn add react-virtual-scrolling or react-virtual-scrolling.

Usage

To use the component, In your react Application just do


render() {
    return (
        <div ref="list" onScroll={this.scrollList}>
            <VirtualScroll
                {...this.props}
                ref="virtualScroll"
                rows={this.data} // data of around 50000 rows
                scrollContainerHeight={400} // height of the container that would remain visible
                totalNumberOfRows={(this.data.length) || 0}
                rowHeight={25} // for now, only fixed height rows can be rendered in the component
                rowRenderer={this.contentRenderer.bind(this)} // function for rendering different type of lists 
            />
        </div> 
    );
  }


  renderRows(fromRow, toRow, styles) {
    const generatedRows = [];
    for (let i = fromRow; i < toRow; i++) {
      generatedRows.push(<li style={styles}>{ 'List item' + (i+1) }</li>);
    }
    return generatedRows;
  }

  scrollList(e) {
    if (this.refs.virtualScroll) {
      this.refs.virtualScroll.scrollHook(e.target);
    }
  }

  contentRenderer(rowStyles, fromRow, toRow, parentStyles) {
    return (
      <ul style={parentStyles}> // complete control on list styling 
        {this.renderRows(fromRow, toRow, rowStyles)}
      </ul>
    );
  }

Demo

Please find the working example of the above component here https://kritika2808.github.io/virtual-scroll/#/list

Restriction

Fixed height rows can be rendered for now.

Upcoming versions

Upcoming versions are going to include 'buffering/caching' feature while scrolling.