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-pageless-scroll

v0.0.1

Published

Pageless scrolling React component that renders only visible items

Downloads

6

Readme

react-pageless-scroll

react-pageless-scroll is a react container component that provides an sliding window of infinite pageless content when the following conditions are met:

  • The dimensions of the the space in which to render the pageless content is known
  • The dimensions of each item of content to be paginated are fixed, known and consistent between items

How it works

react-pageless-scroll is a react component container that accepts your list of content as children and wraps each in a div that it is able to position itself. By specifying the dimensions on the scrollable area and that of each list item, react-pageless-scroll is able to position and render only the items on-screen, allowing the user to scroll through incredibly long lists of content without any browser slowdown.

When should I user react-pageless-scroll?

If your users are not experiencing any slowdown scrolling through the content you have, then you should probably not use this module. Browsers are better optimised for translating, scrolling and painting only what is visible in the current window.

However, if your users are experiencing slowdown due to rendering many, many HTML elements or your content includes links that, when returned from, should resume at the point in the list where you left off, then react-pageless-scroll may be for you.

Stability

This component is still in its infancy and breaking changes may occur in future updates.

Props

Position & Scrolling

style

react-pageless-scroll requires a style prop with the attributes height and width that describe the dimensions of the space to render the pageless content in pixels, as an integer. You are also able to place other attributes on this object that will be applied to the outermost div that wraps the scrollable area.

The two properties you cannot override, however, are overflow and position as these are required for react-pageless-scroll to work correctly.

itemStyle

Similar to style, the itemStyle object must contain width and height. Optionally, margin, marginRight, marginLeft, marginTop and marginBottom are also accepted to control the spacing between list items. If both specified, the more specific margin attributes override margin. If left undefined, the default value is 0.

initialScrollPosition

This controls where in the list the pageless list should start. It must be specified in pixels and defaults to 0.

onScroll

A callback that is called each time the list is scrolled, that receives the current scroll position, in pixels from the original starting position. Any action you perform in this callback must be efficient, as it will be executed many times per second during scrolling.

You can use onScroll to save the current scroll position outside the component so that when you re-render the pageless list (after following a link, for example) you can have the user resume at the same place they left off.

Loading more results

moreToLoad

This boolean value indicates whether there are more results available and whether onLoadMore should be called when the user reaches the bottom of the list.

onLoadMore

A callback to be executed when the list reaches the bottom of the list. It is expected this callback will load more content from the server and re-render component with more children. It receives no arguments.

loadThreshold

An integer that describes how many pixels from the bottom of the list, onLoadMore should be called. The higher the number, the sooner more content is loaded and the less likely the user is going to hit the bottom.

Examples

let scrollPosition = 0;

function recordScrollPosition(newScrollPosition){
  scrollPosition = newScrollPosition;
}

const ListContainer = React.createClass({
 const {hasMore} = this.state;
 
 render: function(){
   const itemStyle = {
     width: 400,
     height: 500,
     margin: 10
   };
     
   const style = {
     width: window.innerWidth,
     height: window.innerHeight
   };
   
   <PagelessScroll
    style={style}
    itemStyle={itemStyle}
    onLoadMore={this.loadNextPage}
    moreToLoad={hasMore}
    onScroll={recordScrollPosition}
    initialScrollPosition={scrollPosition}
    >

    {this.renderPagelessContent()}

  </PagelessScroll>
 },
 
 renderPagelessContent: function(){
   // return list of content
 },
 
 loadNextPage: function(){
   // fetch more results
 }
});

Caveats

The scroll bar will no longer accurately reflect your user's progress of scrolling through your list. If this is important to you, you will need to render some other visual indicator to the user, using the current scroll position, and the number and dimensions of your list items.

Future work

  • Build out the available callbacks to include when content appears and disappears on screen
  • Include the ability to specify a preloader while more results are being retrieved