Socket
Socket
Sign inDemoInstall

react-infinite-scrollable

Package Overview
Dependencies
3
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-infinite-scrollable

react utility


Version published
Weekly downloads
11
increased by83.33%
Maintainers
1
Install size
14.0 kB
Created
Weekly downloads
 

Readme

Source

react-infinite-scrollable

react-infinite-scrollable is a lightweight and easy-to-use React component that enables infinite scrolling functionality in your web applications. With this package, you can effortlessly implement infinite scrolling for long lists, grids, or any other content that needs to be dynamically loaded as the user scrolls.

Installation

To get started with react-infinite-scrollable, simply install the package via npm:

$ npm install react-infinite-scrollable --save

Usage

import React from "react";
import InfiniteScrollable from "react-infinite-scrollable";

function YourComponent() {
  const [page, setPage] = useState(1);
  const [hasMore, setHasMore] = useState(true);
  const [loading, setLoadig] = useState(true);
  const [article, setArticle] = useState([]);

  const fetchPost = () => {
    setLoadig(true);
    fetch(`https://jsonplaceholder.typicode.com/posts?_page=${page}&_limit=10`)
      .then((data) => {
        setData((old) => [...old, ...data]);
      })
      .catch((error) => {
        setHasMore(false);
        console.log({ error });
      })
      .finally(() => {
        setLoadig(false);
      });
  };

  useEffect(() => {
    fetchPost();
  }, [page]);

  const loadMore = () => {
    setPage((pre) => pre + 1);
  };
  return (
    <InfiniteScrollable
      onEnd={loadMore}
      loading={loading}
      hasMore={hasMore}
      loadingComponent={<center>my custom loading component</center>}
      noMoreComponent={<center>my custom No more Post</center>}
      offset={300}
    >
      {articles.map((article) => (
        <div key={article.id} style={{ marginBottom: 16 }}>
          <h2>{article.title}</h2>
          <p>{article.body}</p>
        </div> // your component here
      ))}
    </InfiniteScrollable>
  );
}

Parameters Table

NameDescriptionTypeDefault
hasMoreIndicates whether there are more items to load.booleantrue
loadingIndicates whether the component is currently loading more items.booleanfalse
loadingComponentOptional loading component to display while loading.React.ReactNode<center>loading..</center>
noMoreComponentOptional no more data component to display.React.ReactNode<center>no more</center>
onEndA function to load more items.Function-
offsetThe offset value to trigger loading more items.Number0

Keywords

FAQs

Last updated on 12 Apr 2024

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