# react-use-infinite-scroll-list

> react utility hooks - Infinite scroll list

Latest version **0.0.2-dev4** (published 2020-09-03) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2-dev4 |
| Published | 2020-09-03 |
| First published | 2020-09-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 70.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | amati |
| Maintainers | amati |
| Keywords | react, hooks, infinite scroll |

## Links

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

## Dependencies (1)

- [intersection-observer](https://npm.io/package/intersection-observer.md) ^0.11.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.0.2-dev4 (latest) — 2020-09-03
- 0.0.2-dev2 — 2020-09-03

## README

# react-use-infinite-scroll-list

React hooks - Infinite Scroll List powered by `IntersectionObserver`

## 🎊 Install

```shell
npm install react-use-infinite-scroll-list
```

## 📝 Usage

```js
import useInfiniteScrollList from 'react-use-infinite-scroll-list';

const YOUR_COMPONENT = () => {
  // hooks initialize
  const [items, setItems] = useState([]);
  const { InfiniteScrollList } = useInfiniteScrollList({
    init: init,
    more: more,
    loadingElement: <div>Loading...</div>,
  });

  // init : fetch first data
  async function init() {
    return new Promise((resolve, reject) => {
      YOUR_API()
        .then((res) => {
          // ...
          setItems([res.items]);
          resolve({
            isDone: res.isDone,
          });
        })
        .catch((error) => {
          // ...
          reject(error);
        });
    });
  }

  // more : fetch more data when scrolling to bottom of list
  async function more() {
    return new Promise((resolve, reject) => {
      YOUR_API()
        .then((res) => {
          // ...
          setItems([...items, res.items]);
          resolve({ isDone: res.isDone });
        })
        .catch((error) => {
          // ...
          reject(error);
        });
    });
  }

  return (
    <>
      <InfiniteScrollList>
        <YourListComponent items={items} />
      </InfiniteScrollList>
    </>
  );
};
```

### 🔧 Props

- `init` : a callback function to fetch first-page data. you should return a Promise resolve with `isDone` value.
- `more` : a callback function to fetch more data when scrolling to the end of list. you should return a Promise resolve with `isDone` value.
- `loadingElement` : (optional) JSX Component to display on a bottom of list while executing `more` callback

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