
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
react-waypoint-jk
Advanced tools
A React component to execute a function whenever you scroll to an element.
A React component to execute a function whenever you scroll to an element. Works in all containers that can scroll, including the window.
React Waypoint can be used to build features like lazy loading content, infinite scroll, or docking elements to the viewport on scroll.
Inspired by Waypoints, except this little library grooves the React way.
npm install react-waypoint --save
var Waypoint = require('react-waypoint');
<Waypoint
onEnter={this._handleWaypointEnter}
onLeave={this._handleWaypointLeave}
/>
A waypoint normally fires onEnter
and onLeave
as you are scrolling, but it
can fire because of other events too:
onEnter
if it's visible on the page)Callbacks will only fire if the new position changed from the last known
position. Sometimes it's useful to have a waypoint that fires onEnter
every
time it is updated as long as it stays visible (e.g. for infinite scroll). You
can then use a key
prop to control when a waypoint is reused vs. re-created.
<Waypoint
key={cursor}
onEnter={this._loadMoreContent}
/>
propTypes: {
/**
* Function called when waypoint enters viewport
* Both parameters will be null if the waypoint is in the
* viewport on initial mount.
*
* @param {Event|null} event
* @param {Waypoint.above|Waypoint.below|null} from
*/
onEnter: PropTypes.func,
/**
* Function called when waypoint leaves viewport
*
* @param {Event|null} event
* @param {Waypoint.above|Waypoint.below} to
*/
onLeave: PropTypes.func,
/**
* Threshold - a percentage of the height of the visible
* part of the scrollable parent (e.g. 0.1)
*/
threshold: PropTypes.number,
/**
* Scrollable Parent - A custom parent to determine if the
* target is visible in it. This is useful in cases where
* you do not want the immediate scrollable ancestor to be
* the container. For example, when your target is in a div
* that has overflow auto but you are detecting onEnter based
* on the window.
*/
scrollableParent: PropTypes.any,
/**
* FireOnRapidScroll - if the onEnter/onLeave events are to be fired
* on rapid scrolling
*/
fireOnRapidScroll: PropTypes.bool,
},
In this component we make a few assumptions that we believe are generally safe, but in some situations might present limitations.
window
if no scrollable container is found). This
means that if your scrollable container has a height that is greater than the
window, it might trigger onEnter
unexpectedly.Credit to trotzig and lencioni for writing this component, and the Brigade team for open sourcing it.
Thanks to the creator of the original Waypoints library, imakewebthings.
FAQs
A React component to execute a function whenever you scroll to an element.
We found that react-waypoint-jk demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.