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-infinity-loading

v1.0.1

Published

Event-driven, fully-controlled infinite scroll loading for React, especially for mobile

Downloads

18

Readme

react-infinity-loading

npm code style: prettier

:surfer:Event-driven, fully-controlled infinite scroll loading for React

Why

There are a lot of infinite scroll components out there, and I tried some of them, which usually handles and hide many details inside, and you can't control every phase when you scroll down the page, which makes it really unpredictable in some cases, and as a result, I have to create yet another component to let you control every part of the scroll phases based on a simple event emitter.

Usage

npm i react-infinity-loading --save or yarn add react-infinity-loading

and in your component:

import InfiniteLoading, {emitter, TYPE, EventEmitter} from 'react-infinity-loading';
//demo loading component
import Loading from 'react-infinity-loading/components/Loading';

class App extends React.Component {
  constructor(props) {
    //default emitter exported
    this.emitter = emitter;
    //or create a new EventEmitter instance to prevent conflict with the default one if you have multiple InfiniteLoading instances on the same page
    // this.emitter = new EventEmitter();
    
    //add handler after the <InfiniteLoading> initialized before user scroll, usually when page loaded 
    this.initLoadingListener = this.emitter.addListener(TYPE.INIT_LOADING, () => {
      //load your own data
      this.loadData();
    });
    //handler for page scroll when the <InfiniteLoading> may be visible
    this.loadingListener = this.emitter.addListener(TYPE.LOADING, () => {
      //load your own data when user scroll to page bottom
      this.loadData();
    });
  }
  
  componentWillUnmount() {
    //remove event listener before unmount
    this.initLoadingListener.remove();
    this.loadingListener.remove();
  }
  
  render() {
    return (
      <div>
        <ul>
          <li></li>
          {/*... your list map*/}
        </ul>
        <InfiniteLoading className="custom-css-class" delay={1000} loader={<Loading/>}/>
      </div>
    )
  }
}

Events

Fired from InfiniteLoading component

  • TYPE.INIT_LOADING: fired on component initialization(usually on page loaded)
  • TYPE.LOADING: fired every time when user scroll to the bottom, this is when you need to load more data from your api

Fired by you

  • TYPE.LOADING_FINISHED: every time after you load more chunk of data, emit this event to notify InfiniteLoading to finish the current loading phase
  • TYPE.ALL_LOADED: when you've done loading all your data, you should notify InfiniteLoading to stop listen for user scroll by emitter.emit(TYPE.ALL_LOADED).
  • TYPE.REINITIALIZE: sometimes when you changed the search filters, you may need to reset the loading status/pagination, this is the event you need to tell InfiniteLoading to reset all events, and re-init the scroll process, just like the first initialization.

Demo

Open ./build/index.html in your browser, and start scroll down the page.

LICENSE

MIT @ 2017-2018 jason