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-lazy-infinite

v1.0.1

Published

Infinite scrollable list of same height item lazy loaded with an automatic detection of the heigth

Downloads

5

Readme

react-lazy-infinite

After trying redux-infinite-scroll and react-infinite, I had to adapt them to fit my needs and I ended up starting over.

This module is a lot inspired on the work mention above. Thanks guys !

I decided to publish this in case someone find himself with the same use cases that I struggled with. If it doesn't fit your need, lookup react-infinite and redux-infinite-scroll

Installation

npm install --save react-lazy-infinite

You also need a need a generator polyfill like babel-polyfill.

Peer dependencies

Version 15.x.x

  • react
  • react-dom
  • react-addons-pure-mixin

What is it ?

A solution for long scrollable lists with SAME-HEIGHT-items

Features

  • Lazy load/fetch/prepare the data with props.fetchMore when approaching the last item (given with the props totalNumberOfItems)
  • Automatically calculated height
  • For performance purposes, only the visible items and a few buffer items are rendered

Limits

  • All items must have the same height: This is to allow the height to be automatically calculated. The height of the first item to be rendered is assume to be the same height than all the items.

Props

containerStyle

  • PropTypes.object
  • Inline style for the container

containerTypea

  • PropTypes.string
  • Default to 'tbody'
  • The container of the items

hasMore

  • PropTypes.bool.isRequired
  • Tells when to stop fetching

initialNumberOfItems

  • PropTypes.number
  • Default to 15
  • Since the height of the items can only be calculated once rendered, the initial render can not know how many items to render
  • Once an item is rendered, componentHeight / itemHeight is used

loader

  • PropTypes.node.isRequired
  • Element or component to render to let the user know it's fetching/loading

totalNumberOfItems

  • PropTypes.number.isRequired
  • Number of items

fetchMore (numberOfVisibleItems)

  • PropTypes.func.isRequired
  • Function to call to fetch more items for the initial fetch and the lazy-load fetch when approaching the bottom of the list

renderItems (fromIndex, toIndex)

  • PropTypes.func.isRequired
  • Fonction to get the items component to render

Example

...
import InfiniteScroll from 'react-lazy-infinite'

class MyList extends React.Component {
  static propsType {
    fetchIngredients: PropTypes.func.isRequired,
    ingredients: PropTypes.array.isRequired,
    hasMoreIngredientsToFetch: PropTypes.bool.isRequired
  }

  render () {
    return (
      </table>
        <InfiniteScroll
          fetchMore={this.props.fetchIngredients}
          hasMore={this.props.hasMoreIngredientsToFetch}
          loader={<tr><td>Keep smiling, we're almost there...</td></tr>}
          renderItems={this.renderIngredientEntries}
          totalNumberOfItems={this.props.ingredients.length}
        />
      </table>
    )
  }

  renderIngredientEntries = (startIndex, endIndex) => {
    const ingredientsToDisplay = this.props.ingredients.slice(startIndex, endIndex + 1)
    const ingredientsEntries = ingredientsToDisplay.map(
      (i) => <IngredientEntry key={i.id} {...i} />
    )
    return ingredientsEntries
  }
}

Contributions

Always welcome ! I'm sure you can help making this better :)