
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
react-intersection
Advanced tools

React Intersection provides a simple component-based interface to the Intersection Observer API.
It provides two core components: IntersectionElement and IntersectionRoot.
IntersectionElement adds its direct DOM child as an observer of the nearest parent IntersectionRoot, or the browser viewport if none found.IntersectionRoot optionally creates a new IntersectionObserver with either the browser viewport or its direct DOM child as the observed root.IntersectionObserverEntry object to each onChange handler. A great low-level starting point for more specific functionality.Nodes to set IntersectionObserver.root.npm install react-intersection --save
By default, wrapping a component with IntersectionElement will subscribe its first child DOM element to a default viewport IntersectionObserver, with threshold set to [0, 1].
This means onChange will fire when the element is first fully and partially off/on screen.
import { IntersectionElement } from 'react-intersection';
class Item extends React.Component {
state = {
isIntersecting: false
};
setVisibility = ({ isIntersecting }) => this.setState({ isIntersecting });
render() {
return (
<IntersectionElement onChange={this.setVisibility}>
<li />
</IntersectionElement>
);
}
}
rootWe can use a parent element as the IntersectionObserver.root instead of the viewport:
import { IntersectionRoot } from 'react-intersection';
const ScrollableList = () => (
<IntersectionRoot>
<ul>
{renderItems()}
</ul>
</IntersectionRoot>
);
In the above example, ul will be the root of the new IntersectionObserver that any children IntersectionElements will subscribe to.
To create a new browser viewport root with non-default settings, we can pass a viewport prop to IntersectionRoot:
const IntersectViewportWithMargins = ({ children }) => (
<IntersectionRoot viewport margin="20px 20px 20px 20px">
{children}
</IntersectionRoot>
);
IntersectionElementObserve when an element intersects with its closest IntersectionRoot
onChange: (e: IntersectionObserverEntry) => anyFires after every breached threshold on the IntersectionRoot (or browser viewport if none set).
Is provided an IntersectionObserverEntry object.
once?: boolean = falseStops firing events after the first true intersection.
IntersectionRootDefine a new IntersectionObserver.
If no root property is defined, it only accepts a single child.
viewport?: boolean = falseIf true, sets the browser viewport as the IntersectionObserver.root property. If false, uses the first DOM child.
margin?: string = '0px 0px 0px 0px'A space-delimited list of margins that effectively change the observed bounding box.
Follows the CSS pattern of top/right/bottom/left where '10px 20px 30px 40px' would give a right margin of 20px.
If IntersectionRoot is not a viewport observer, these values can be defined as percentages.
threshold?: number[] = [0, 1]An array of values between 0 and 1 that dictates at which ratios the IntersectionObserver should fire callbacks. Thresholds are fully explained in the MDN Intersection Observer API article.
React Intersection is dependent on the IntersectionObserver API and WeakMap:
FAQs
A React interface for the Intersection Observer API
The npm package react-intersection receives a total of 34 weekly downloads. As such, react-intersection popularity was classified as not popular.
We found that react-intersection demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.