Socket
Socket
Sign inDemoInstall

use-infinite-scroll

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    use-infinite-scroll

A react hook to use infinite scroll


Version published
Maintainers
1
Install size
541 kB
Created

Readme

Source

use-infinite-scroll

A react hook to use infinite scroll

NPM JavaScript Style Guide

Install

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

Demo

https://y2507wpz01.codesandbox.io/

Usage

import React, { useState, useEffect } from 'react'
import useInfiniteScroll from 'use-infinite-scroll'

const Example = () => {
  // Note: If you don't set initial value for items,
  // use useEffect(fetchData, []) to load data initially,
  // see example/src/App.js for usecase
  const [ items, setItems ] = useState(Array.from(Array(30).keys(), n => n + 1));
  const [isFetching, setIsFetching] = useInfiniteScroll(fetchData)

  // replace this with your own data fetch function
  function fetchData() {
    setTimeout(() => {
      setItems(prevItems =>
        ([...prevItems, ...Array.from(Array(20).keys(), n => n + prevItems.length + 1)])
      );
      setIsFetching(false);
    }, 2000);
  }

  return (
    <div>
      <ul>
        {items.map(item => <li key={item}>{item}</li>)}
      </ul>
      {isFetching ? 'Fetching...' : 'Not Fetching'}
    </div>
  )
}
// see this code live at https://y2507wpz01.codesandbox.io/

License

MIT © abdullahtariq1171


created using create-react-hook.

FAQs

Last updated on 30 Apr 2019

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