Skip to content
A simple infinite loading list in React
JavaScript HTML CSS
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
example Improve example functionality and ui (#25) Oct 18, 2019
src
.all-contributorsrc 👥 Add gVirtu as a contributor (#30) Oct 25, 2019
.babelrc
.editorconfig 🔧 Init create-react-library@2.6.7 Aug 26, 2019
.eslintrc
.gitignore
.travis.yml
CHANGELOG.md 🔖 Release 1.0.0-alpha.7 Oct 25, 2019
CODE_OF_CONDUCT.md
LICENSE
README.md
package-lock.json
package.json
rollup.config.js

README.md

react-simple-infinite-loading

NPM JavaScript Style Guide gitmoji-changelog

Why?

I wrote an article about creating an infinite loading list with React and GraphQL. Someone pointed out the React implementation of the list was a bit complex. I figure out it was possible to write an abstraction for this particular case. Here it is!

This component aims to stay easy to use. If your use case needs more options I recommend using directly awesome libraries from Brian Vaughn listed in dependencies section.

Demo

You can find a demo here.

Install

npm install --save react-simple-infinite-loading

Usage

import React from 'react'

import InfiniteLoading from 'react-simple-infinite-loading'

function Example({ items, fetchMore, hasMore }) {
  return (
    <div style={{ width: 300, height: 300 }}>
      <InfiniteLoading
        hasMoreItems={hasMore}
        itemHeight={40}
        loadMoreItems={fetchMore}
      >
        {items.map(item => <div key={item}>{item}</div>)}
      </InfiniteLoading>
    </div>
  )
}

Link to example

Dependencies

react-simple-infinite-loading has only three dependencies:

  • react-window is made to display efficiently large lists. It only creates components for the visible elements and reuse nodes.
  • react-window-infinite-loader is a HOC that loads elements just-in-time as user scrolls down the list
  • react-virtualized-auto-sizer helps you displaying your list so it fits the space available in its parent container.

Properties

property name required type description
children yes function The children function should return the jsx for an item of the list. An object is passed as parameter containing item, index, style. You must pass the style to top-level tag of your item's jsx.
items yes array An array of elements. Any type of elements is accepted.
itemHeight yes number The height of an item. All items should have the same height.
itemsCount no number The count of items to be loaded, if known. Prevents the scrollbar from changing its size as the items are being loaded.
hasMoreItems no boolean A boolean that determines if there are still items to load using loadMoreItems function.
loadMoreItems no function A function that will be called each time the list need to load more items.
placeholder no node Any render-able value like strings or React.Nodes to be displayed while children is loading

License

Apache-2.0 © frinyvonnick

Contributors

Thanks goes to these wonderful people (emoji key):

Yvonnick FRIN
Yvonnick FRIN

📖
Augusto
Augusto

📖
Henrique Martins
Henrique Martins

📖
Yoann Prot
Yoann Prot

📖
Jimmy Kasprzak
Jimmy Kasprzak

💻
Kerem Hallaç
Kerem Hallaç

💻
Tim
Tim

📖 💻
Giancarlo França
Giancarlo França

💻

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

You can’t perform that action at this time.