# use-infinite-scroll

> A react hook to use infinite scroll

Latest version **0.1.1** (published 2019-04-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install use-infinite-scroll
pnpm add use-infinite-scroll
yarn add use-infinite-scroll
bun add use-infinite-scroll
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2019-04-30 |
| First published | 2019-04-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=8 |
| Dependencies | 0 |
| Unpacked size | 541.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | abdullahtariq1171 |
| Maintainers | abdullahtariq1171 |

## Links

- npm: https://www.npmjs.com/package/use-infinite-scroll
- Repository: https://github.com/abdullahtariq1171/use-infinite-scroll
- Homepage: https://github.com/abdullahtariq1171/use-infinite-scroll#readme
- Issues: https://github.com/abdullahtariq1171/use-infinite-scroll/issues
- npm.io page: https://npm.io/package/use-infinite-scroll

## Recent versions

- 0.1.1 (latest) — 2019-04-30
- 0.1.0 — 2019-04-26
- 0.0.1 — 2019-04-26

## README

# use-infinite-scroll

> A react hook to use infinite scroll

[![NPM](https://img.shields.io/npm/v/use-infinite-scroll.svg)](https://www.npmjs.com/package/use-infinite-scroll) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

## Install

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

## Demo

https://y2507wpz01.codesandbox.io/

## Usage

```jsx
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](https://github.com/abdullahtariq1171)

---

created using [create-react-hook](https://github.com/hermanya/create-react-hook).

---
_Source: https://npm.io/package/use-infinite-scroll · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
