# list-renderer

> > 基础知识: [与 scroll 相关的方法](https://github.com/Witee/keep-learning/issues/12)

Latest version **1.1.1** (published 2020-12-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install list-renderer
pnpm add list-renderer
yarn add list-renderer
bun add list-renderer
```

## 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.1.1 |
| Published | 2020-12-22 |
| First published | 2020-12-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 0 |
| Unpacked size | 32.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Witee |
| Maintainers | witee |
| Keywords | 分批加载, 滚动加载, 虚拟滚动, 列表滚动加载, react, list, virtual list |

## Links

- npm: https://www.npmjs.com/package/list-renderer
- Homepage: https://github.com/Witee/list-renderer
- npm.io page: https://npm.io/package/list-renderer

## 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

- 1.1.1 (latest) — 2020-12-22
- 1.1.0 — 2020-12-22
- 1.0.2 — 2020-12-21
- 1.0.1 — 2020-12-21
- 1.0.0 — 2020-12-21

## README

# list-renderer

> 基础知识: [与 scroll 相关的方法](https://github.com/Witee/keep-learning/issues/12)

批量渲染列表, 优化性能.

应用场景:

可以一次性拿到所有列表数据, 滚动到底部时可以自动加载一部分新数据, 再次滚动可以再次加载, 直到全部加载完成.

| 参数       | 是否必选 | 类型          | 说明                                                                    |
| ---------- | -------- | ------------- | ----------------------------------------------------------------------- |
| children   | 是       | JSX.Element[] | 需要批量加载的元素列表                                                  |
| pageSize   | 是       | number        | 每页渲染的数量                                                          |
| loader     | 否       | JSX.Element   | 加载时底部显示的加载指示符                                              |
| onFinish   | 否       | function      | 全部加载完成后的回调                                                    |
| refreshKey | 否       | any           | 此值更新时将重新获取 children 参数, 否则一直使用第一次加载时的 children |

示例代码如下:

[demo](https://codesandbox.io/s/list-renderer-basic-cyygg?file=/src/App.tsx)

#### 使用`refreshKey` 的情况:

[demo](https://codesandbox.io/s/blissful-wood-3wwtz)

如果是一个列表, 如果 `a[]` 在做为`useEffect` 的依赖时, 会认为每次都是个新的对象, 这里将`key`转换为字符串 `refreshKey={_items.map((i) => i.key).join()` 作为依赖参数, 可以解决这个问题.

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