Installations
npm install react-bottom-scroll-listener
Score
87.6
Supply Chain
93.3
Quality
75.8
Maintenance
100
Vulnerability
99.6
License
Releases
Contributors
Developer
Developer Guide
Module System
CommonJS
Min. Node Version
>=10
Typescript Support
Yes
Node Version
16.15.0
NPM Version
8.5.5
Statistics
150 Stars
121 Commits
15 Forks
2 Watching
3 Branches
7 Contributors
Updated on 09 Nov 2024
Bundle Size
3.46 kB
Minified
1.42 kB
Minified + Gzipped
Languages
TypeScript (58.64%)
JavaScript (37.02%)
HTML (3.25%)
CSS (1.08%)
Total Downloads
Cumulative downloads
Total Downloads
5,438,354
Last day
5.5%
8,266
Compared to previous day
Last week
42.6%
44,277
Compared to previous week
Last month
15%
137,870
Compared to previous month
Last year
70%
2,039,728
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Dev Dependencies
27
react-bottom-scroll-listener
A simple React hook and React component that lets you listen for when you have scrolled to the bottom.
Window
Container
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:
1useBottomScrollListener(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
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
1import { useBottomScrollListener } from 'react-bottom-scroll-listener'; 2 3useBottomScrollListener(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
1import { useBottomScrollListener } from 'react-bottom-scroll-listener'; 2 3const scrollRef = useBottomScrollListener(callback); 4 5<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
On bottom of entire screen
Simply have the BottomScrollListener anywhere in your application and pass it a function as onBottom
-prop.
1import BottomScrollListener from 'react-bottom-scroll-listener'; 2 3<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.
1import BottomScrollListener from 'react-bottom-scroll-listener'; 2 3<BottomScrollListener onBottom={callback}> 4 {(scrollRef) => <div ref={scrollRef}>Callback will be invoked when this container is scrolled to bottom.</div>} 5</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. :)
No vulnerabilities found.
Reason
14 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 10
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
1 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
Reason
Found 2/23 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/build-test.yml:1
- Info: topLevel 'contents' permission set to 'read': .github/workflows/gh-pages.yml:9
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build-test.yml:9: update your workflow using https://app.stepsecurity.io/secureworkflow/karl-run/react-bottom-scroll-listener/build-test.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/build-test.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/karl-run/react-bottom-scroll-listener/build-test.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/build-test.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/karl-run/react-bottom-scroll-listener/build-test.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/gh-pages.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/karl-run/react-bottom-scroll-listener/gh-pages.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/gh-pages.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/karl-run/react-bottom-scroll-listener/gh-pages.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/gh-pages.yml:37: update your workflow using https://app.stepsecurity.io/secureworkflow/karl-run/react-bottom-scroll-listener/gh-pages.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/gh-pages.yml:39: update your workflow using https://app.stepsecurity.io/secureworkflow/karl-run/react-bottom-scroll-listener/gh-pages.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/gh-pages.yml:44: update your workflow using https://app.stepsecurity.io/secureworkflow/karl-run/react-bottom-scroll-listener/gh-pages.yml/main?enable=pin
- Info: 0 out of 7 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 11 are checked with a SAST tool
Score
4
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to react-bottom-scroll-listener
react-scroll-to-bottom
React container that will auto scroll to bottom
react-infinite-scroll-hook
A simple hook to create infinite scroll components
@types/react-scroll-to-bottom
TypeScript definitions for react-scroll-to-bottom
react-remove-scroll
Disables scroll outside of `children` node.