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

use-fetch-infinite-scroll

v1.0.4

Published

infinite pagination react package hook for react and js fetch method.

Downloads

9

Readme

use-fetch-infinite-scroll

A React hook for infinite scrolling with data fetching from a REST API endpoint.

Installation

You can install the package via npm or yarn:

npm install use-fetch-infinite-scroll
yarn add use-fetch-infinite-scroll

Example

import React from 'react';
import useFetchInfiniteScroll from 'use-fetch-infinite-scroll';

const InfiniteScrollComponent = () => {
	const { data, loading, hasMore, lastItemRef } = useFetchInfiniteScroll({
		endpoint: '/api/items',
		limit: 10,
		sortOrder: 'asc',
		filters: { category: 'books' }
	});
	
	return (
		<div>
			{data.map((item, index) => (
				<div key={item._id} ref={index === data.length - 1 ? lastItemRef : null}>
					{item.name}
				</div>
			))}
			{loading && <p>Loading...</p>}
			{!hasMore && <p>No more items</p>}
		</div>
	);
};

export default InfiniteScrollComponent;

Props

  • endpoint - The API endpoint to fetch data from.
  • limit - The number of items to retrieve per request.
  • **sortOrder ** - The order to sort the items (asc for ascending, desc for descending)
  • **filters ** - An object containing key-value pairs to filter the items.
  • idKey - The key to use as the unique identifier for each item.
  • dataKey - The key to use to access the array of items in the response data.
  • fetchOptions - Additional options to pass to the fetch function.

License

This project is licensed under the MIT License.

Development

To start development, use the following command:

yarn dev

This will start both the client and server development environments. The stories for development can be found in the stories directory.

Scripts

  • dev: Concurrently runs the client and server development environments.
  • client-dev: Starts the Vite development server.
  • server-dev: Starts the server using nodemon.
  • build: Builds the project using TypeScript and Vite.
  • preview: Previews the built project using Vite.