Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cloversites/redux-infinite-scroll

Package Overview
Dependencies
Maintainers
2
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cloversites/redux-infinite-scroll

React infinite scroll component designed for a Redux data-flow.

  • 1.0.9-76f362a
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
2
Weekly downloads
 
Created
Source

Circle CI npm version npm dm Package Quality

Redux Infinite Scroll

A stateless React infinite scroll component meant for usage within Redux.

Important

If you are using an element as the scrollable component, rather than the window, you MUST pass a fixed height to the containerHeight prop (many issues will be fixed by following this step).

Demo & Examples

http://realscout.github.io/redux-infinite-scroll/

Installation

npm install redux-infinite-scroll --save

Importing Via AMD/CommonJS

ES6 format
import ReduxInfiniteScroll from 'redux-infinite-scroll';
ES5 format
var ReduxInfiniteScroll = require('redux-infinite-scroll');

Importing Via Script Tag

If you decide to use either one of the distribution files found in /dist, then you can access the ReduxInfiniteScroll via a global variable.

ES6 format
ReduxInfiniteScroll
ES5 format
ReduxInfiniteScroll.default;

The difference is due to the ReduxInfiniteScroll being an ES6 module and therefore having a different export syntax than ES5.

Usage

In order to use it in your React app, simply import it and follow the example below. The component expects to receive child elements that it then injects into the DOM. The loadMore prop expects a function that requests for more items to be loaded once the container/window has reached the bottom threshold. If there are no more items left to be passed to the component, make sure to set the hasMore prop to be false. Important If you are using an element as the scrollable component, rather than the window, you MUST pass a fixed height to the containerHeight prop.

ES6 format

// MessageList.jsx

import InfiniteScroll from 'redux-infinite-scroll';
import ChatActions from './ChatActions';

class MessageList extends Component {
  _loadMore() {
    this.props.dispatch(ChatActions.fetchMessages())
  }
  
  _renderMessages() {
    return _.map(this.props.messages, (msg) => {
      return(
          <div>{msg}</div>
      )
    })
  }
  
  render() {
    return (
        <InfiniteScroll
          items={this._renderMessages()}
          loadMore={this._loadMore.bind(this)}
        />
    )
  }
}

Where your Redux action and reducer might look something like this:

// ChatActions.js

export function fetchMessages(params) {
  return {
    type: FETCH_MESSAGES,
    messages: ['hi there', 'hi again', 'still here']
  };
}


// ChatReducer.js


const initialState = {
  messages: []
}

function chatReducer(state=initialState, action=undefined) {
  switch (action.type) {
    case FETCH_MESSAGES:
      return Object.assign({}, initialState, {
        messages: initialState.concat(action.messages)
      })
  }
}

Options

PropsTypeRequiredDefaultDescription
elementIsScrollableboolnotrueDefines whether the div will have a fixed height and listens to the div's overflow event or instead have a non-fixed height and listen to the window scroll event
containerHeightinteger or stringno'100%'Sets an inline style on the height of the topmost div.
thresholdintegerno100The number of pixels from the bottom that the scroll bar must reach in order to trigger loadMore.
horizontalboolnofalseWhether to check for horizontal scrolling
hasMoreboolnotrueWhether there are more items waiting to be displayed. Set this to false once all of the items have been passed down to either items or children.
loadingMoreboolnofalseA prop that should be set to true by the parent component whenever the loadMore function gets invoked, and then toggled to false once that function has finished updating the items prop.
loaderanynoLoading...The value of this prop gets injected as the last element of the parent div when hasMore loadingMore and showLoader are all true.
showLoaderboolnotrueWhether to show the loader when the loadingMore property is true
loadMorefunctionyesundefinedThe function is called when the component has reached the threshold and hasMore is true.
holderTypestringnodivThe type the loader is rendered as, could be ul, dl, etc.
classNamestringno''Any additional classes to be added to the holder.
itemsarrayno[]The array of elements waiting to be rendered. Use either this or children. Deprecated.
childrenarrayno[]The array of elements waiting to be rendered. Use either this or items.

Credits

RealScout Heavily inspired by react-infinite-scroll.

License

MIT Licensed. Copyright (c) RealScout Inc.

Keywords

FAQs

Package last updated on 05 Dec 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc