npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-scrollable-feed

v2.0.1

Published

<h1 align="center" style="border-bottom: none;">react-scrollable-feed</h1> <h3 align="center">Smart scrolling for chat UIs and feeds</h3> <p align="center"> <a href="https://github.com/dizco/react-scrollable-feed/actions/workflows/main.yml"> <img al

Downloads

18,993

Readme

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:
if (element.scrollBy) {
  element.scrollBy({ top: offset });
}
else {
  element.scrollTop = 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 React.PropsWithChildren<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.

onScroll

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

Is called when the onScroll event is triggered on the wrapper div created by ScrollableFeed.

Provides isAtBottom boolean value as a parameter, which indicates if the scroll is at bottom position, taking viewableDetectionEpsilon into account.

Public Methods

scrollToBottom

  • Signature: () => void

Scroll to the bottom

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 :star:
  • Create pull requests, submit bugs, suggest new features or documentation updates :wrench:. See contributing doc.

License

BSD 3-Clause © Gabriel Bourgault

See license.