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-virtualist

v1.0.6

Published

πŸ’€πŸšŸ Dead-simple react virtual scroll library

Downloads

6

Readme

react-virtualist

πŸ’€πŸšŸ Just a dead-simple react library to render big list (~1M) by rendering only visible elements (with a few offset of course)

Pros

  • Render only if needed & visible
  • Few dependencies (only react and prop-types)
  • Dead-simple (see KISS principle)
  • Self-contained (no alteration on parent)
  • Scroll attached to body
  • Valid wrapper component height
  • No problems if header or footer
  • "Fast" update (use vlid, check complex example with 1M items re-rendered every 100ms, and try to scroll)
  • Configurable offset
  • Compatible with placeholder

Cons

  • Only horizontal
  • Only body scroll
  • Fixed item height

Example

Tips: use a parent when rendering your item, specific item style can alter your component style & behavior

Simple

import React, {Component} from 'react'
import VirtuaList from 'react-virtualist'

class Simple extends Component {
  render(){
    return (
      <div>
        <h1 style={{height: '200vh', background: 'green'}}>Header</h1>
        <VirtuaList
          height={100}
          items={[
            'Henry Fonda',
            'Lee J. Cobb',
            'Martin Balsam',
            'Jack Klugman',
            'Ed Begley',
            'John Fiedler',
            'E. G. Marshall',
            'Jack Warden',
            'Joseph Sweeney',
            'Robert Webb',
            'Jiri Voskovec',
            'Ed Binns',
            'Rudy Bond',
            'Billy Nelson'
          ]}
          render={(actor, index, style) => {
            return (
              <div key={index} style={Object.assign({ background: 'red' }, style)} vlid={'vlid' + index}>
                <p>Hello #{actor}</p>
              </div>
            )
          }}
        />
        <h1 style={{height: '200vh', background: 'blue'}}>Footer</h1>
      </div>
    )
  }
}

Complex

Usage with placeholders, prefer simple variable for items (string or number), object are complex to compare and so the library feature of render only if visible will not work

import React, {Component} from 'react'
import VirtuaList from 'react-virtualist'

class Complex extends Component {
  constructor(props){
    super(props)

    this.state = {
      videos: [
        'FKkhLWjN_I4',
        'J3sq8tculJM',
        '0U_g1z1CeqU',
        '405EwMgtlyg',
        'FmUDe7P0fzg',
        'ENMrJoEwO4Q',
        'QDdSSQpua_g',
        '8Ri-sT8DVeg',
        'v-e7p_IG0nY',
        'eUw9aolPlog',
        'LtrUSZ-Kcns'
      ],
      total: 1000000 // suppose we're currently fetching others and we want placeholders for empty
    }
  }

  componentDidMount(){
    // suppose we're currently fetching others and we want placeholders for empty
    const videos = this.state.videos
    const interval = setInterval(() => {
      videos.push(Math.random().toString(36).substr(2, 11))

      if (videos.length > this.state.total) {
        clearInterval(interval)
      }

      this.setState(videos)
    }, 100)
  }

  render(){
    return (
      <VirtuaList
        height={20}
        items={[].concat(this.state.videos, Array(this.state.total - this.state.videos.length).fill(null))}
        render={(id, row, style) => {
          return (
            <div key={row} style={Object.assign({ width: '100%' }, style)}>
              { id ? <a href={ 'https://youtu.be/' + id }>{ id }</a> : <p>Fetching...</p> }
            </div>
          )
        }}
        offset={5}
        style={{
          width: '100%'
        }}
      />
    )
  }
}

Build

Commit anything before running theses commands, then:

  • npm run build
  • npm version x.x.x
  • git push
  • git push --tags
  • npm publish

More

Thanks