# react-use-infinite-loading

> Infinite scroll hook for React. Supports multiple scroll directions.

Latest version **1.1.5** (published 2020-08-23) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.5 |
| Published | 2020-08-23 |
| First published | 2020-08-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 0 |
| Unpacked size | 22.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | evankazadaiev |
| Maintainers | evan_kazadaiev |
| Keywords | react-infinite-scroll, react-infinite-scroll-hook, react-infinite-scroller, react-use-infinite-scroll, use-infinite-scroll, react infinite scroll, react use infinite scroll, infinite scroll, react-infinite-scrolling, react infinite scroller, react infinite scrolling, react scrolling, infinite scrolling |

## Links

- npm: https://www.npmjs.com/package/react-use-infinite-loading
- Repository: https://github.com/evankazadaiev/use-infinite-loading-hook
- Homepage: https://github.com/evankazadaiev/use-infinite-loading-hook#readme
- Issues: https://github.com/evankazadaiev/use-infinite-loading-hook/issues
- npm.io page: https://npm.io/package/react-use-infinite-loading

## Recent versions

- 1.1.5 (latest) — 2020-08-23
- 1.1.4 — 2020-08-14
- 1.1.3 — 2020-08-13
- 1.1.2 — 2020-08-13
- 1.1.1 — 2020-08-13
- 1.1.0 — 2020-08-13
- 1.0.0 — 2020-08-10

## README

# react-use-infinite-loading

> Infinite scroll hook for React

[![NPM](https://img.shields.io/npm/v/react-use-infinite-scroll.svg)](https://www.npmjs.com/package/react-use-infinite-scroll) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

## DEMO
https://evankazadaiev.github.io/use-infinite-loading-hook/

## Install

```bash
NPM 
npm install --save react-use-infinite-loading
-------------
YARN
yarn add react-use-infinite-loading
```

## Options

| Option        | Type |  Description     | Required |  Default value  |
| --------------|:-------:| :------------:|:--------:|:---------------:|
| callback      |Function | api request   | true     |-                |
| hasMore       | Boolean |   if server has more items for us | true | - |
| startPage     | Number  |  Start page   | false    | 1 |
| offset | Number |Distance for sending request before end of scrolling container | false | 250 |
| direction | String // top or bottom | Scroll direction | false | bottom |
 
## Usage

```tsx
import React from 'react'
import useInfiniteLoading from 'react-use-infinite-loading'


const Example = () => {
  const [pokemons, setPokemons] = useState(null);
  
  const getImages = (page) => new Promise(async (resolve) => {
    const res = await getPokemons(page, 100);
    setPokemons(prev => (prev ? [...prev, ...res] : res));
  
    resolve(res);
  });
  

  const [ref, containerRef, isLoading] = useInfiniteScroll({
    hasMore: true, // if server-side has more items for us
    offset: 100, // send request 100px before the end of scrolling container
    direction: 'bottom', // scroll direction
    callback: getImages, // api request
  });

  return (
    <div ref={containerRef}>
      <ul className="gallery">
        {pokemons &&
        pokemons.map((pokemon, idx) => (
            <Child {...pokemon} key={idx}/>
          ))}
      </ul>
      <Loader ref={ref}>{ isLoading && <Spinner color="goldenrod" size="64px" thickness={2} />}</Loader>
    </div>
  );
};
```

## License

MIT © [evankazadaiev](https://github.com/evankazadaiev)

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