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-list-window

v0.1.1

Published

`react-list-window` is a package designed to simplify the rendering of large and extensive lists in your web applications. Managing large lists efficiently can be a challenging task, leading to performance issues and slow loading times. This package provi

Downloads

3

Readme

React List Window

react-list-window is a package designed to simplify the rendering of large and extensive lists in your web applications. Managing large lists efficiently can be a challenging task, leading to performance issues and slow loading times. This package provides an elegant solution through "windowing," allowing you to display only the visible portion of your list at any given time.

Installation

You can install this component using your preferred package manager. For example, using npm:

npm install react-list-window

Or using yarn:

yarn add react-list-window

Usage

1. Import Components

First, import components:

import { List, Data } from "react-window-list";

2. Define API Function and Props

The List component needs an API function to fetch data page by page. This is a simple example of an API Function accepting an abort controller signal:

const apiFn = (page, pageSize, signal) =>
    new Promise((resolve, reject) => {
        signal.addEventListener("abort", () => {
            reject(new DOMException("Aborted", "AbortError"));
        });

        resolve({
            data: posts.slice(page * pageSize, (page + 1) * pageSize),
            hasNextPage: (page + 1) * pageSize < manyPosts.length,
            page,
            pageSize,
            total: posts.length,
        });
    });

and the props will be like below:

const props = useMemo(
    () => ({
        apiFn,
        orientation: "vertical",
        pageSize: 100,
        fixedSize: false,
        autoLoad: true,
    }),
    []
);

3. Create List Component With Data Provider

You can get all data from Data component like below. You must pass a function rendering elements that are wrapped with Windowed component.

<List {...props}>
   <Data<Post>>
      {(state) =>
         state.data.map((d) => (
            <Windowed key={d.id}>
                  <Post post={d} />
            </Windowed>
         ))
      }
   </Data>
</List>

Note: You don't necessarily need to wrap components with Windowed. This component is responsible for windowing and will not be applied if you don't use it.

4. Add Trigger Component

With Trigger you can control when to load a new page. Whenever the button element enters viewport handleLoadMore function will be called. It can be disabled by passing loadMore={false} as a property.

<Trigger>
    {({ handleLoadMore, enterCount, loading, hasNextPage }) => (
        <button onClick={handleLoadMore}>
            Load More {loading && "Loading!"} enterCount: {enterCount} hasNextPage{" "}
            {hasNextPage ? "YES" : "NO"}
        </button>
    )}
</Trigger>

Contributions

We welcome contributions from the community to enhance this package. If you have ideas for improvements, bug fixes, or new features, please feel free to contribute.

Before making any changes, we encourage you to open an issue on our GitHub repository to discuss your proposed contribution. This helps ensure that your contribution aligns with the project's goals and guidelines.