Gathering detailed insights and metrics for @shopify/react-intersection-observer
Gathering detailed insights and metrics for @shopify/react-intersection-observer
Gathering detailed insights and metrics for @shopify/react-intersection-observer
Gathering detailed insights and metrics for @shopify/react-intersection-observer
[⚠️ Deprecated] A loosely related set of packages for JavaScript/TypeScript projects at Shopify
npm install @shopify/react-intersection-observer
Typescript
Module System
Min. Node Version
Node Version
NPM Version
96.6
Supply Chain
91
Quality
82.4
Maintenance
100
Vulnerability
100
License
@shopify/react-i18n-universal-provider@3.1.8
Updated on Jan 10, 2025
@shopify/react-i18n@7.14.0
Updated on Jan 10, 2025
@shopify/name@1.3.0
Updated on Jan 10, 2025
@shopify/dates@2.1.1
Updated on Jan 10, 2025
@shopify/react-i18n-universal-provider@3.1.7
Updated on Jan 10, 2025
@shopify/react-i18n@7.13.2
Updated on Jan 10, 2025
TypeScript (96.39%)
Ruby (2.34%)
JavaScript (1.23%)
Shell (0.02%)
CSS (0.02%)
Total Downloads
15,375,381
Last Day
122
Last Week
6,647
Last Month
33,376
Last Year
1,255,045
MIT License
1,692 Stars
4,974 Commits
226 Forks
386 Watchers
249 Branches
7,205 Contributors
Updated on Jun 04, 2025
Minified
Minified + Gzipped
Latest Version
4.1.0
Package Id
@shopify/react-intersection-observer@4.1.0
Unpacked Size
22.52 kB
Size
5.36 kB
File Count
30
NPM Version
10.7.0
Node Version
18.20.3
Published on
Jun 10, 2024
Cumulative downloads
Total Downloads
1
2
@shopify/react-intersection-observer
A React wrapper around the Intersection Observer API.
1yarn add @shopify/react-intersection-observer
useIntersection(options: Options)
The useIntersection
hook takes in IntersectionObserver
options, and returns a tuple of:
ref
to the DOM element you wish to track.1function MyComponent() { 2 const [intersection, intersectionRef] = useIntersection(); 3 4 return ( 5 <div ref={intersectionRef}>Intersection: {intersection.isIntersecting}</div> 6 ); 7}
You can pass additional options to this hook that are used to create the underlying IntersectionObserver
:
threshold
: a number or array of number indicating the intersectionRatio
that must be met before the observer is triggered.root
: a string or element that is used as the viewport for visibility testing. If a string is passed, it will be treated as a selector.rootMargin
: a string representing the margins by which to shrink the root’s bounding box before computing intersections.<IntersectionObserver />
This package also exports an IntersectionObserver
component, which is a fairly minimal component wrapper around the useIntersection
hook, and accepts the same threshold
, root
, and rootMargin
values as props. The onIntersectionChange
prop you pass to this component will be called with an IntersectionObserverEntry
object, which describes the state of the intersection (and is equivalent to the first value of the tuple returned from the hook).
Unlike the useIntersection
hook, this component will create its own DOM node that will be observed, rather than requiring you to pass a ref
to a DOM node you already control. You can customize the rendered markup by passing either of the following props:
children
, which will be rendered inside of the node being observed for intersections.wrapperComponent
, which changes the DOM node being wrapped around those children (defaults to a div
).1<div ref={this.parentElement}> 2 <IntersectionObserver 3 root={this.parentElement.current} 4 rootMargin="10px 10%" 5 threshold={1} 6 onIntersectionChange={(entry) => 7 console.log('intersectionRatio > 0', entry) 8 } 9 onNotIntersecting={(entry) => console.log('intersectionRatio = 0', entry)} 10 /> 11</div>
When useIntersection
is passed new options (or, when IntersectionObserver
receives new props), this library will do the minimum amount of work to unobserve/ re-observe with the new fields. The most expensive updates to make are changing threshold
, root
, rootMargin
, and, in the case of the component version, wrapperComponent
, as these require disconnecting the old observer and recreating a new one.
When a component consuming the useIntersection
hook is unmounted, the intersection observer is disconnected. The same applies if you unmount an IntersectionObserver
component.
To polyfill IntersectionObserver
, please use the @shopify/polyfills/intersection-observer
package.
If you do not polyfill the feature and it is not supported in the current browser, the useIntersection
hook and the IntersectionObserver
component will decide what to do based on the unsupportedBehavior
option. This value should be a member of the UnsupportedBehavior
enum (exported from this package). Currently, there are two options:
UnsupportedBehavior.TreatAsIntersecting
: immediately sets state/ calls onIntersectionChange
on mount with a non-0 intersectionRatio
(this is the default).UnsupportedBehavior.Ignore
: never calls marks the intersection observer as being intersecting.No vulnerabilities found.
Reason
all changesets reviewed
Reason
30 commit(s) and 3 issue activity found in the last 90 days -- score normalized to 10
Reason
license file detected
Details
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
security policy file detected
Details
Reason
8 existing vulnerabilities detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-07-01
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 MoreLast Day
-51%
122
Compared to previous day
Last Week
-23.2%
6,647
Compared to previous week
Last Month
-53.8%
33,376
Compared to previous month
Last Year
-52.1%
1,255,045
Compared to previous year