# react-window-scroll

> Virtual scroll component

Latest version **1.0.2** (published 2021-08-13) · ISC license · 0 weekly downloads

## Install

```sh
npm install react-window-scroll
pnpm add react-window-scroll
yarn add react-window-scroll
bun add react-window-scroll
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2021-08-13 |
| First published | 2021-08-11 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 47.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Yogesh Singh |
| Maintainers | iyogeshsingh |

## Links

- npm: https://www.npmjs.com/package/react-window-scroll
- Repository: https://github.com/gs-ysingh/react-window-scroll
- Homepage: https://github.com/gs-ysingh/react-window-scroll#readme
- Issues: https://github.com/gs-ysingh/react-window-scroll/issues
- npm.io page: https://npm.io/package/react-window-scroll

## Recent versions

- 1.0.2 (latest) — 2021-08-13
- 1.0.1 — 2021-08-11
- 1.0.0 — 2021-08-11

## README

# React Virtual Scroll
Handle large list in react

## Installation
yarn add react-window-scroll

or 

npm i react-window-scroll

## Example 1: Virutal scroll
```
import React, { useMemo } from "react";

import VirtualScroll from "react-window-scroll";

const App = () => {
  const itemRow = ({ name, key }) => {
    return (
      <div
        key={key}
        className="item-row"
        style={{
          height: "40px",
          border: "1px solid blue",
          lineHeight: "40px",
          boxSizing: "border-box",
        }}
      >
        {name}
      </div>
    );
  };

  const getData = () => {
    return Array(10000)
      .fill({})
      .map((_, index) => {
        return { key: index, name: (Math.random() + 1).toString(36).substring(7) };
      });
  };

  const data = useMemo(() => {
    return getData();
  }, []);

  return (
    <div
      style={{
        border: "1px solid blue",
      }}
    >
      <VirtualScroll
        data={data}
        height={400}
        itemCount={10000}
        itemHeight={40}
        RowComponent={itemRow}
      />
    </div>
  );
};
```

## Example 2: Infinite scroll
```
const App = () => {
  const [data, setData] = useState<Array<Item>>([]);
  const itemRow = ({ name, key }) => {
    return (
      <div
        key={key}
        className="item-row"
        style={{
          height: "40px",
          border: "1px solid blue",
          lineHeight: "40px",
          boxSizing: "border-box",
        }}
      >
        {name}
      </div>
    );
  };

  const getData = () => {
    return new Promise((resolve) => {
      setTimeout(() => {
        const result = Array(100)
          .fill({})
          .map((_, index) => {
            return { key: index, name: (Math.random() + 1).toString(36).substring(7) };
          });
        resolve(result);
      }, 3000);
    });
  };

  const loadMore = () => {
    getData().then((res: Array<Item>) => {
      setData([...data, ...res]);
    });
  };

  useEffect(() => {
    getData().then((res: Array<Item>) => {
      setData(res);
    });
  }, []);

  return (
    <div
      style={{
        border: "1px solid blue",
      }}
    >
      <VirtualScroll
        data={data}
        height={400}
        itemCount={data.length}
        itemHeight={40}
        loadMore={loadMore}
        RowComponent={itemRow}
      />
    </div>
  );
};
```

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