Socket
Socket
Sign inDemoInstall

@closeio/use-infinite-scroll

Package Overview
Dependencies
8
Maintainers
5
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @closeio/use-infinite-scroll

Super simple React hook for creating an infinite scroll experience based on the IntersectionObserver API


Version published
Weekly downloads
123
increased by4.24%
Maintainers
5
Install size
21.1 kB
Created
Weekly downloads
 

Readme

Source

use-infinite-scroll

NPM JavaScript Style Guide

Super simple React hook for creating an infinite scroll experience based on the IntersectionObserver API.

Check the live DEMO.

Interested in working on projects like this? Close is looking for great engineers to join our team!

Install

yarn add @closeio/use-infinite-scroll

Benefits

  • Extremely lightweight (less than 1KB minzipped).
  • It uses the IntersectionObserver API, so it doesn't need to listen to scroll events – which are known to cause performance issues.
  • No other 3rd-party dependencies.

Usage

import React from 'react';
import useInfiniteScroll from '@closeio/use-infinite-scroll';

const [items, setItems] = useState([]);
const [hasMore, setHasMore] = useState(false);
const [page, loaderRef, scrollerRef] = useInfiniteScroll({ hasMore });

useEffect(async () => {
  const data = await myApiCall({ page });
  setHasMore(data.hasMore);
  setItems(prev => [...prev, data.items]);
}, [page]);

return (
  <div ref={scrollerRef}>
    {items.map(item => (
      <div key={item.id}>{item.name}</div>
    ))}
    {hasMore && <div ref={loaderRef}>Loading…</div>}
  </div>
);

License

MIT © Close

FAQs

Last updated on 23 Mar 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc