All Projects → frinyvonnick → react-simple-infinite-loading

frinyvonnick / react-simple-infinite-loading

Licence: Apache-2.0 License
A list that infinitely loads content as user scrolls down in React

Programming Languages

javascript
184084 projects - #8 most used programming language
CSS
56736 projects
HTML
75241 projects

Projects that are alternatives of or similar to react-simple-infinite-loading

Google Books Android Viewer
Android library to bridge between RecyclerView and sources like web page or database. Includes demonstrator (Google Books viewer)
Stars: ✭ 37 (-33.93%)
Mutual labels:  infinite-scroll, ui-components
ng-mono-repo-starter
Angular Mono Repo Starter
Stars: ✭ 79 (+41.07%)
Mutual labels:  ui-components
open design system
Open Source Design System using Sketch. It's early days of my project.
Stars: ✭ 22 (-60.71%)
Mutual labels:  ui-components
dashkit-ui
UI Components built on React.
Stars: ✭ 17 (-69.64%)
Mutual labels:  ui-components
mijin
Tailwind CSS UI components build for Vue.js / Nuxt.js
Stars: ✭ 168 (+200%)
Mutual labels:  ui-components
phoenix component folders
Reusable UI components on Phoenix framework
Stars: ✭ 31 (-44.64%)
Mutual labels:  ui-components
oojs-ui
OOUI is a modern JavaScript UI library with strong cross-browser support. It is the standard library for MediaWiki and Wikipedia. This is a mirror from https://gerrit.wikimedia.org. Main website:
Stars: ✭ 45 (-19.64%)
Mutual labels:  ui-components
react-awesome-notifications
A beautiful fully customizable React + Redux notification system built with styled-components
Stars: ✭ 29 (-48.21%)
Mutual labels:  ui-components
business-hours-picker
A business hours picker and viewer for android
Stars: ✭ 31 (-44.64%)
Mutual labels:  ui-components
wlui
wl-ui 精美易用的前端复杂组件解决方案。Beautiful and easy-to-use front-end complex component solution
Stars: ✭ 32 (-42.86%)
Mutual labels:  ui-components
a11y-accordion-tabs
A script for an accessible accordion tabs component
Stars: ✭ 50 (-10.71%)
Mutual labels:  ui-components
anim search bar
A flutter package that has an animated search bar with loads of customization
Stars: ✭ 28 (-50%)
Mutual labels:  ui-components
flextreemap
TreeMap data visualization component for Adobe Flex
Stars: ✭ 22 (-60.71%)
Mutual labels:  ui-components
Bulma.io-axure
AxureRP Library with Bulma.io components
Stars: ✭ 90 (+60.71%)
Mutual labels:  ui-components
native-kitchensink
📱 Playground for ReactiveSearch Native components
Stars: ✭ 46 (-17.86%)
Mutual labels:  ui-components
jqlouds
☁️ An awesome yet simple plugin for jquery that let's you create clouds on the fly.
Stars: ✭ 54 (-3.57%)
Mutual labels:  ui-components
wonder-blocks
React components for Wonder Blocks design system.
Stars: ✭ 110 (+96.43%)
Mutual labels:  ui-components
CheckMarkView
UI view which draws programmatically a checkmark with different styles
Stars: ✭ 35 (-37.5%)
Mutual labels:  ui-components
SwimplyPlayIndicator
Animated PlayIndicator written in SwiftUI. Inspired by Apple's Music Player.
Stars: ✭ 52 (-7.14%)
Mutual labels:  ui-components
evolution-ui
Cutting Edge UI Components for Modern Developers
Stars: ✭ 30 (-46.43%)
Mutual labels:  ui-components

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
customScrollbar no boolean A boolean that determines if react-custom-scrollbars is used instead of native one
elementClassName no string A React className prop that will be applied to every child container
ref no ref or function A ref or a callback ref to get component instance so you can call instance's methods (see Methods section)

Methods

scrollTo(scrollOffset: number): void

see FixedSizeList methods section.

scrollToItem(index: number, align: string = "auto"): void

see FixedSizeList methods section.

resetloadMoreItemsCache(): void

Clear previously loaded items from cache.

example

import React from 'react'

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

function Example({ items, fetchMore, hasMore }) {
  const ref = React.useRef()
  const scrollToTop = () => {
    if (ref.current) {
      ref.current.scrollTo(0)
    }
  }
  const scrollTo50 = () => {
    if (ref.current) {
      ref.current.scrollToItem(50)
    }
  }
  const resetCache = () => {
    if (ref.current) {
      ref.current.resetloadMoreItemsCache()
    }
  }

  return (
    <>
      <button onClick={scrollToTop}>Scroll to top</button>
      <button onClick={scrollTo50}>Scroll to 50</button>
      <button onClick={resetCache}>Reset cache</button>
      <div style={{ width: 300, height: 300 }}>
        <InfiniteLoading
          hasMoreItems={hasMore}
          itemHeight={40}
          loadMoreItems={fetchMore}
          ref={ref}
        >
          {items.map(item => <div key={item}>{item}</div>)}
        </InfiniteLoading>
      </div>
    </>
  )
}

License

Apache-2.0 © frinyvonnick

Contributors

Thanks goes to these wonderful people (emoji key):


Yvonnick FRIN

📖

Augusto

📖

Henrique Martins

📖

Yoann Prot

📖

Jimmy Kasprzak

💻

Kerem Hallaç

💻

Tim

📖 💻

Giancarlo França

💻

Giles

💻

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].