JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7653
  • Score
    100M100P100Q160980F
  • License MIT

Package Exports

  • react-scrollable-feed

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-scrollable-feed) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

react-scrollable-feed

Smart scrolling for chat UIs and feeds

Build Status Cypress Dashboard NPM latest version JavaScript Style Guide PRs Welcome

dependencies Status peerDependencies Status devDependencies Status

UX-wise, asking a user to scroll down manually a chat box when new messages arrive is quite painful. react-scrollable-feed aims to alleviate the burden of managing scrolling concerns from React developers. The same concept applies to any other kind of feed where new content arrives dynamically.

Demo

View a live demo here.

Live demo gif

Install

npm install --save react-scrollable-feed

Usage

import * as React from 'react'

import ScrollableFeed from 'react-scrollable-feed'

class App extends React.Component {
  render() {
    const items = ['Item 1', 'Item 2'];

    return (
      <ScrollableFeed>
        {items.map((item, i) => <div key={i}>{item}</div>)}
      </ScrollableFeed>
    );
  }
}

Options

forceScroll

  • Type: boolean
  • Default: false

If set to true, will scroll to the bottom after each update on the component. By default, if the scrollable section is not at the bottom before the update occurs, it will leave the scroll at the same position.

animateScroll

  • Type: (element: HTMLElement, offset: number) => void
  • Default: element.scrollBy({ top: offset });

Allows to override the scroll animation by any implementation.

onScrollComplete

  • Type: () => void
  • Default: () => {}

Is called after the scroll animation has been executed.

changeDetectionFilter

  • Type: (previousProps: ScrollableFeedComponentProps, newProps: ScrollableFeedComponentProps) => boolean
  • Default: () => true

Allows to customize when the scroll should occur. This will be called everytime a componentDidUpdate happens, which means everytime one of the props changes. You will receive as parameters the previous and the new props.

Note: ScrollableFeedComponentProps is defined as Readonly<{ children?: ReactNode }> & Readonly<ScrollableFeedProps>

If you want to compare the last children from both the previous and new props, you could do something like this :

import * as React from 'react'

import ScrollableFeed from 'react-scrollable-feed'

class App extends React.Component {
  changeDetectionFilter(previousProps, newProps) {
    const prevChildren = previousProps.children;
    const newChildren = newProps.children;

    return prevChildren !== newChildren
      && prevChildren[prevChildren.length - 1] !== newChildren[newChildren.length - 1];
  }

  render() {
    const items = ['Item 1', 'Item 2'];

    return (
      <ScrollableFeed
        changeDetectionFilter={this.changeDetectionFilter}
      >
        {items.map((item, i) => <div key={i}>{item}</div>)}
      </ScrollableFeed>
    );
  }
}

export default App;

className

  • Type: string
  • Default: undefined

CSS class that can be added on the wrapping div created by ScrollableFeed.

viewableDetectionEpsilon

  • Type: number
  • Default: 2

Indicates the number of pixels of difference between the actual bottom and the current position that can be tolerated. The default setting should be fine for most use cases.

For more details

For more details on how to integrate react-scrollable-feed in your application, have a look at the example folder.

Contibuting

  • Star this GitHub repo ⭐
  • Create pull requests, submit bugs, suggest new features or documentation updates 🔧. See contributing doc.

License

MIT © Gabriel Bourgault