All Projects → karl-run → react-bottom-scroll-listener

karl-run / react-bottom-scroll-listener

Licence: other
A simple listener component that invokes a callback when the webpage is scrolled to the bottom.

Programming Languages

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

Projects that are alternatives of or similar to react-bottom-scroll-listener

packetevents
PacketEvents is a powerful packet library. Our packet wrappers are efficient and easy to use. We support many protocol versions. (1.8+)
Stars: ✭ 235 (+82.17%)
Mutual labels:  listener
chrome-mouse-wheel-tab-scroller
Scroll Google Chrome tabs using mouse wheel
Stars: ✭ 39 (-69.77%)
Mutual labels:  scroll
use-gesture
👇Bread n butter utility for component-tied mouse/touch gestures in React and Vanilla Javascript.
Stars: ✭ 6,624 (+5034.88%)
Mutual labels:  scroll
scrolltotop
Scroll To Top extension for Chrome, Firefox, Safari, Opera.
Stars: ✭ 60 (-53.49%)
Mutual labels:  scroll
scrollpup.js
Minimal beautiful bar to show scroll progress. Pure Javascript Plugin.MIT
Stars: ✭ 83 (-35.66%)
Mutual labels:  scroll
angular2-infinite-scroll
Infinite Scroll Directive For Angular (version 2 up to 2.3.1)
Stars: ✭ 16 (-87.6%)
Mutual labels:  scroll
seamless-scroll-polyfill
Scroll Behavior polyfill
Stars: ✭ 134 (+3.88%)
Mutual labels:  scroll
use-scroll-direction
A simple, performant, and cross-browser hook for detecting scroll direction in your next react app.
Stars: ✭ 24 (-81.4%)
Mutual labels:  scroll
scrollbounce
Add a subtle bounce effect on mobile when the user scrolls (WIP)
Stars: ✭ 17 (-86.82%)
Mutual labels:  scroll
SSCycleScrollView
轮播终结者,用swift完成,易用集成
Stars: ✭ 39 (-69.77%)
Mutual labels:  scroll
use-smooth-scroll
React hook which gives a smooth scrolling function.
Stars: ✭ 41 (-68.22%)
Mutual labels:  scroll
really-smooth-scroll
A script that smoothen scrolling in the browser
Stars: ✭ 21 (-83.72%)
Mutual labels:  scroll
EasyScrollDots
Single page scroll JavaScript plugin that allows for vertical navigation of page sections
Stars: ✭ 38 (-70.54%)
Mutual labels:  scroll
JDropDownAlert
Simple DropDown Alert View For Any iOS Projects.
Stars: ✭ 71 (-44.96%)
Mutual labels:  bottom
BackToMe
Little tool made in python to create payloads for Linux, Windows and OSX with unique handler
Stars: ✭ 61 (-52.71%)
Mutual labels:  listener
spydriver
🕵️ Lightweight utility to intercept WebDriver and WebElement method calls.
Stars: ✭ 24 (-81.4%)
Mutual labels:  listener
Flask-Validator
Validator for SQLAlchemy Models
Stars: ✭ 27 (-79.07%)
Mutual labels:  listener
OverScroll
Use CoordinatorLayout+Behavior to achieve elastic scrolling and inertial scrolling for list. 利用CoordinatorLayout+Behavior实现弹性滚动和惯性滚动效果(类似微信首页).
Stars: ✭ 37 (-71.32%)
Mutual labels:  scroll
AppListManager
📱 AppListManager (Android Library) makes managing application and activity lists easy.
Stars: ✭ 59 (-54.26%)
Mutual labels:  listener
slider-manager
simple wrapper to create sliders focused on animations
Stars: ✭ 28 (-78.29%)
Mutual labels:  scroll

react-bottom-scroll-listener npm NPM version npm bundle size (minified)

A simple React hook and React component that lets you listen for when you have scrolled to the bottom.

Window

Example

Container

Example

Installation

npm: npm install react-bottom-scroll-listener

yarn: yarn add react-bottom-scroll-listener

Migrating to V5

Version 5 is only a refactor for the hook to use an options parameter, instead of relying of function parameters which were starting to get out of hand.

If you are using the component, there are no breaking changes

If your hook looks like this:

useBottomScrollListener(callback, 0, 200, undefined, true);

You will have to change it to use the options parameter:

useBottomScrollListener(callback, {
  offset: 100,
  debounce: 0,
  triggerOnNoScroll: true
})

Remember that you can omit any values that are using the defaults! The defaults are ase following:

  offset: 0,
  debounce: 200,
  debounceOptions: { leading: true },
  triggerOnNoScroll: false,

So for the average use case, you are probably only setting one of these values, so your hook might look like this:

useBottomScrollListener(callback, { triggerOnNoScroll: true })

You can refer to the Usage-section for more details.

Usage

Hook

Full example

On bottom of entire screen

Use the hook in any functional component, the callback will be invoked when the user scrolls to the bottom of the document

import { useBottomScrollListener } from 'react-bottom-scroll-listener';

useBottomScrollListener(callback);

On bottom of specific container

Use the hook in any functional component, use the ref given from the hook and pass it to the element you want to use as a scroll container

The callback will be invoked when the user scrolls to the bottom of the container

import { useBottomScrollListener } from 'react-bottom-scroll-listener';

const scrollRef = useBottomScrollListener(callback);

<div ref={scrollRef}>Callback will be invoked when this container is scrolled to bottom.</div>;

Parameters

useBottomScrollListener<T extends HTMLElement>(
  // Required callback that will be invoked when scrolled to bottom
  onBottom: () => void,
  // Options, entirely optional, you can provide one or several to overwrite the defaults
  options?: {
    // Offset from bottom of page in pixels. E.g. 300 will trigger onBottom 300px from the bottom of the page
    offset?: number
    // Optional debounce in milliseconds, defaults to 200ms
    debounce?: number
    // Overwrite the debounceOptions for lodash.debounce, default to { leading: true }
    debounceOptions?: DebounceOptions
    // If container is too short, enables a trigger of the callback if that happens, defaults to false
    triggerOnNoScroll?: boolean
  },
); // returns React.MutableRefObject Optionally you can use this to pass to a element to use that as the scroll container

Component

Full example

On bottom of entire screen

Simply have the BottomScrollListener anywhere in your application and pass it a function as onBottom-prop.

import BottomScrollListener from 'react-bottom-scroll-listener';

<BottomScrollListener onBottom={callback} />;

On bottom of specific container

Pass the BottomScrollListener a function inside the JSX_tag, receive the scrollRef in this function from the BottomScrollListener and pass it to the component you want to listen for a scroll event on.

import BottomScrollListener from 'react-bottom-scroll-listener';

<BottomScrollListener onBottom={callback}>
  {(scrollRef) => <div ref={scrollRef}>Callback will be invoked when this container is scrolled to bottom.</div>}
</BottomScrollListener>;

Those are some weird children, what's going on?

This pattern is called "function as a child". What this allows is that the BottomScrollListener can pass you a React.RefObject. This React.RefObject can then be passed to whatever component you want to be notified when you hit the bottom of. Without this it would be difficult to attach event listeners for scrolling to an arbitrary element.

Props

Property Type Default Description
onBottom Function null (required): callback invoked when bottom is reached
debounce number 200 milliseconds, how much debounce there should be on the callback
offset number 0 offset from bottom in pixels. E.g. 300 if it should invoke onBottom 300px before the bottom.
debounceOptions DebounceOptions {leading: true} see the lodash.debounce options: see https://lodash.com/docs/4.17.15#debounce
triggerOnNoScroll boolean false if container is too short, enables a trigger of the callback if that happens
children React.Node or Function null Not required, but you can use this to wrap your components. Most useful when you have some conditional rendering. If this is a function, that function will receive a React.RefObject that needs to be passed to a child element. This element will then be used as the scroll container.

Migrating from 2.x.x to 3.x.x

There are no breaking changes except that the required version of React is now 16.8.0. If you are on an older version of React you can either upgrade React, or stay on version 2.x.x. If you already are on a newer version of React you don't have to do anything, except maybe try out the new hook implementation. :)

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].