@amreraky/react-infinite-scroller

中文文档
2.0.7发布于 2026/03/27MITTypeScriptCommonJS零依赖近 30 天下载 2521

Infinite scroll component for React (forked to support React >= 18 and TypeScript)

原始使用文档
文档目录8 节
  1. Installation
  2. How to use
  3. Window scroll events
  4. DOM scroll events
  5. Custom parent element
  6. Props
  7. Troubleshooting
  8. Double or non-stop calls to loadMore

This's a fork of react-infinite-scroller to support React >= 18 and TypeScript

React Infinite Scroller

npm npm npm

Infinitely load a grid or list of items in React. This component allows you to create a simple, lightweight infinite scrolling page or element by supporting both window and scrollable elements.

  • ⏬ Ability to use window or a scrollable element
  • 📏 No need to specify item heights
  • 💬 Support for "chat history" (reverse) mode
  • ✅ Fully unit tested and used in hundreds of production sites around the world!
  • 📦 Lightweight alternative to other available React scroll libs ~ 2.2KB minified & gzipped

Installation

npm install @amreraky/react-infinite-scroller --save

How to use

import InfiniteScroll from '@amreraky/react-infinite-scroller';

Window scroll events

<InfiniteScroll
    pageStart={0}
    loadMore={loadFunc}
    hasMore={true || false}
    loader={<div className="loader" key={0}>Loading ...</div>}
>
    {items} // <-- This is the content you want to load
</InfiniteScroll>

DOM scroll events

<div style="height:700px;overflow:auto;">
    <InfiniteScroll
        pageStart={0}
        loadMore={loadFunc}
        hasMore={true || false}
        loader={<div className="loader" key={0}>Loading ...</div>}
        useWindow={false}
    >
        {items}
    </InfiniteScroll>
</div>

Custom parent element

You can define a custom parentNode element to base the scroll calulations on.

<div style="height:700px;overflow:auto;" ref={(ref) => this.scrollParentRef = ref}>
    <div>
        <InfiniteScroll
            pageStart={0}
            loadMore={loadFunc}
            hasMore={true || false}
            loader={<div className="loader" key={0}>Loading ...</div>}
            useWindow={false}
            getScrollParent={() => this.scrollParentRef}
        >
            {items}
        </InfiniteScroll>
    </div>
</div>

Props

NameRequiredTypeDefaultDescription
childrenYesNodeAnything that can be rendered (same as PropType's Node)
loadMoreYesFunctionA callback when more items are requested by the user. Receives a single parameter specifying the page to load e.g. function handleLoadMore(page) { /* load more items here */ } }
elementComponent'div'Name of the element that the component should render as.
hasMoreBooleanfalseWhether there are more items to be loaded. Event listeners are removed if false.
initialLoadBooleantrueWhether the component should load the first set of items.
isReverseBooleanfalseWhether new items should be loaded when user scrolls to the top of the scrollable area.
loaderComponentA React component to render while more items are loading. The parent component must have a unique key prop.
pageStartNumber0The number of the first page to load, With the default of 0, the first page is 1.
getScrollParentFunctionOverride method to return a different scroll listener if it's not the immediate parent of InfiniteScroll.
thresholdNumber250The distance in pixels before the end of the items that will trigger a call to loadMore.
useCaptureBooleanfalseProxy to the useCapture option of the added event listeners.
useWindowBooleantrueAdd scroll listeners to the window, or else, the component's parentNode.

Troubleshooting

Double or non-stop calls to loadMore

If you experience double or non-stop calls to your loadMore callback, make sure you have your CSS layout working properly before adding this component in. Calculations are made based on the height of the container (the element the component creates to wrap the items), so the height of the container must equal the entire height of the items.

.my-container {
  overflow: auto;
}

This component doesn't make any assumptions about what you do in terms of API calls. It's up to you to store whether you are currently loading items from an API in your state/reducers so that you don't make overlapping API calls.

loadMore() {
  if(!this.state.isLoading) {
    this.props.fetchItems();
  }
}

版本与发布记录

@amreraky/react-infinite-scroller 共发布 8 个版本,首次发布于 2025/05/21;过去 12 个月发布了 3 个版本。

版本发布日期距今
2.0.7latest2026/03/277 个月前
2.0.62026/03/088 个月前
2.0.52026/01/0110 个月前
2.0.42025/08/051.3 年前
2.0.32025/08/051.3 年前
2.0.22025/05/271.4 年前

关于 @amreraky/react-infinite-scroller 的常见问题

@amreraky/react-infinite-scroller 是什么?

Infinite scroll component for React (forked to support React >= 18 and TypeScript)

如何安装 @amreraky/react-infinite-scroller?

在项目目录运行 npm install @amreraky/react-infinite-scroller,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=16.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@amreraky/react-infinite-scroller 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@amreraky/react-infinite-scroller 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@amreraky/react-infinite-scroller 可以商用吗?

@amreraky/react-infinite-scroller 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@amreraky/react-infinite-scroller 的下载量有多少?

根据 npm 官方下载统计,@amreraky/react-infinite-scroller 在 2026/10/06 – 2026/11/04 这 30 天内被下载 2,521 次,日均约 84 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@amreraky/react-infinite-scroller 还在维护吗?

最新版本 2.0.7 发布于 2026/03/27(7 个月前);至今共发布 8 个版本,其中过去 12 个月发布了 3 个;首次发布于 2025/05/21。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。