Launch Week Day 1: Socket for Jira Is Now Available.Learn More โ†’
Socket
Book a DemoSign in
Socket

react-infinite-scroll-component

Package Overview
Dependencies
Maintainers
3
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-infinite-scroll-component

An Infinite Scroll component in react.

latest
Source
npmnpm
Version
7.1.0
Version published
Weekly downloads
1.1M
4.27%
Maintainers
3
Weekly downloads
ย 
Created
Source

react-infinite-scroll-component npm npm

All Contributors

A component to make all your infinite scrolling woes go away with just 4.15 kB! Pull Down to Refresh feature added. An infinite-scroll that actually works and super-simple to integrate!

Install

  npm install --save react-infinite-scroll-component

  or

  yarn add react-infinite-scroll-component

  // in code ES6
  import InfiniteScroll from 'react-infinite-scroll-component';
  // or commonjs
  var InfiniteScroll = require('react-infinite-scroll-component');

Using

<InfiniteScroll
  dataLength={items.length} //This is important field to render the next data
  next={fetchData}
  hasMore={true}
  loader={<h4>Loading...</h4>}
  endMessage={
    <p style={{ textAlign: 'center' }}>
      <b>Yay! You have seen it all</b>
    </p>
  }
  // below props only if you need pull down functionality
  refreshFunction={refresh}
  pullDownToRefresh
  pullDownToRefreshThreshold={50}
  pullDownToRefreshContent={
    <h3 style={{ textAlign: 'center' }}>&#8595; Pull down to refresh</h3>
  }
  releaseToRefreshContent={
    <h3 style={{ textAlign: 'center' }}>&#8593; Release to refresh</h3>
  }
>
  {items}
</InfiniteScroll>

Using scroll on top

<div
  id="scrollableDiv"
  style={{
    height: 300,
    overflow: 'auto',
    display: 'flex',
    flexDirection: 'column-reverse',
  }}
>
  {/*Put the scroll bar always on the bottom*/}
  <InfiniteScroll
    dataLength={items.length}
    next={fetchMoreData}
    style={{ display: 'flex', flexDirection: 'column-reverse' }} //To put endMessage and loader to the top.
    inverse={true}
    hasMore={true}
    loader={<h4>Loading...</h4>}
    scrollableTarget="scrollableDiv"
  >
    {items.map((_, index) => (
      <div style={style} key={index}>
        div - #{index}
      </div>
    ))}
  </InfiniteScroll>
</div>

The InfiniteScroll component can be used in three ways.

  • Specify a value for the height prop if you want your scrollable content to have a specific height, providing scrollbars for scrolling your content and fetching more data.
  • If your scrollable content is being rendered within a parent element that is already providing overflow scrollbars, you can set the scrollableTarget prop to reference the DOM element and use it's scrollbars for fetching more data.
  • Without setting either the height or scrollableTarget props, the scroll will happen at document.body like Facebook's timeline scroll.

What's new in v7

IntersectionObserver-based triggering

next() is now triggered by an IntersectionObserver watching an invisible sentinel element at the bottom of the list (top for inverse mode), rather than a scroll event listener. This means:

  • The threshold is checked once when the sentinel enters the viewport, not on every scroll tick.
  • No missed triggers when content loads fast enough to skip the threshold.
  • Better performance โ€” no work done while the user is scrolling through content that is far from the threshold.

Zero runtime dependencies

throttle-debounce has been removed. The package now ships with zero runtime dependencies. The onScroll callback receives every scroll event directly without throttling.

scrollableTarget accepts HTMLElement directly

Previously scrollableTarget only accepted a string element ID. It now accepts HTMLElement | string | null, so you can pass a ref value directly:

const ref = useRef(null);
// ...
<div ref={ref} style={{ height: 300, overflow: 'auto' }}>
  <InfiniteScroll scrollableTarget={ref.current} ...>
    {items}
  </InfiniteScroll>
</div>

Rewritten as a function component

The component is now a React function component. The public prop API is unchanged โ€” no migration needed.

docs version wise

3.0.2

live examples

  • infinite scroll (never ending) example using react (body/window scroll)
    • Edit yk7637p62z
  • infinte scroll till 500 elements (body/window scroll)
    • Edit 439v8rmqm0
  • infinite scroll in an element (div of height 400px)
    • Edit w3w89k7x8
  • infinite scroll with scrollableTarget (a parent element which is scrollable)
    • Edit r7rp40n0zm

props

nametypedescription
nextfunctiona function which must be called after reaching the bottom. It must trigger some sort of action which fetches the next data. The data is passed as children to the InfiniteScroll component and the data should contain previous items too. e.g. Initial data = [1, 2, 3] and then next load of data should be [1, 2, 3, 4, 5, 6].
hasMorebooleanit tells the InfiniteScroll component on whether to call next function on reaching the bottom and shows an endMessage to the user
childrennode (list)the data items which you need to scroll.
dataLengthnumberset the length of the data.This will unlock the subsequent calls to next.
loadernodeyou can send a loader component to show while the component waits for the next load of data. e.g. <h3>Loading...</h3> or any fancy loader element
scrollThresholdnumber | stringA threshold value defining when InfiniteScroll will call next. Default value is 0.8. It means the next will be called when user comes below 80% of the total height. If you pass threshold in pixels (scrollThreshold="200px"), next will be called once you scroll at least (100% - scrollThreshold) pixels down.
onScrollfunctiona function that will listen to the scroll event on the scrolling container.
endMessagenodethis message is shown to the user when he has seen all the records which means he's at the bottom and hasMore is false
classNamestringadd any custom class you want
styleobjectany style which you want to override
heightnumberoptional, give only if you want to have a fixed height scrolling content
scrollableTargetnode or stringoptional, reference to a (parent) DOM element that is already providing overflow scrollbars to the InfiniteScroll component. You should provide the id of the DOM node preferably.
hasChildrenboolchildren is by default assumed to be of type array and it's length is used to determine if loader needs to be shown or not, if your children is not an array, specify this prop to tell if your items are 0 or more.
pullDownToRefreshboolto enable Pull Down to Refresh feature
pullDownToRefreshContentnodeany JSX that you want to show the user, default={<h3>Pull down to refresh</h3>}
releaseToRefreshContentnodeany JSX that you want to show the user, default={<h3>Release to refresh</h3>}
pullDownToRefreshThresholdnumberminimum distance the user needs to pull down to trigger the refresh, default=100px , a lower value may be needed to trigger the refresh depending your users browser.
refreshFunctionfunctionthis function will be called, it should return the fresh data that you want to show the user
initialScrollYnumberset a scroll y position for the component to render with.
inverseboolset infinite scroll on top

Contributors โœจ

Thanks goes to these wonderful people (emoji key):

Ankeet Maini
Ankeet Maini

๐Ÿ’ฌ ๐Ÿ“– ๐Ÿ’ป ๐Ÿ‘€ ๐Ÿšง
Darsh Shah
Darsh Shah

๐Ÿš‡ ๐Ÿ’ป ๐Ÿ‘€ ๐Ÿšง
Eliya Cohen
Eliya Cohen

๐Ÿ’ป
Nitin Kukreja
Nitin Kukreja

๐Ÿ’ป
Bruno Sabetta
Bruno Sabetta

๐Ÿ’ป ๐Ÿ“–
Osmar Pรฉrez Bautista
Osmar Pรฉrez Bautista

๐Ÿ’ป
Shreya Dahal
Shreya Dahal

๐Ÿ’ป
Vlad Harahan
Vlad Harahan

๐Ÿ’ป ๐Ÿ“–
Daniel Caldas
Daniel Caldas

๐Ÿ’ป
Alaeddine Douagi
Alaeddine Douagi

๐Ÿ’ป
Carlos
Carlos

๐Ÿ’ป
Championrunner
Championrunner

๐Ÿ“–
Daniel Sogl
Daniel Sogl

๐Ÿ’ป
Darren Oster
Darren Oster

๐Ÿ’ป
Illia Panasenko
Illia Panasenko

๐Ÿ’ป
Kiko Beats
Kiko Beats

๐Ÿ’ป
Matt Trussler
Matt Trussler

๐Ÿ’ป
Nimit Suwannagate
Nimit Suwannagate

๐Ÿ’ป
Rajat
Rajat

๐Ÿ’ป
Rich
Rich

๐Ÿ’ป
Ritesh Goyal
Ritesh Goyal

๐Ÿ’ป
babycannotsay
babycannotsay

๐Ÿ’ป
cesco
cesco

๐Ÿ’ป
Harry
Harry

๐Ÿ’ป
ludwig404
ludwig404

๐Ÿ’ป
Karl Johansson
Karl Johansson

๐Ÿ’ป
Geoffrey Teng
Geoffrey Teng

๐Ÿ’ป

This project follows the all-contributors specification. Contributions of any kind are welcome!

LICENSE

MIT

Keywords

react

FAQs

Package last updated on 12 Apr 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts