Gathering detailed insights and metrics for use-element-in-view
Gathering detailed insights and metrics for use-element-in-view
Gathering detailed insights and metrics for use-element-in-view
Gathering detailed insights and metrics for use-element-in-view
react-cool-inview
React hook to monitor an element enters or leaves the viewport (or another element).
use-hot-key-element-v2
Make Hot Key in view easier
use-simple-in-view
Simple React Hook is for monitoring when an element is in the viewport
use-hot-key-element
Make Hot Key in view easier
React hook that utilizes the Intersection Observer API to observe when an element enters and exits the viewport
npm install use-element-in-view
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
4 Stars
35 Commits
1 Forks
1 Watchers
1 Branches
1 Contributors
Updated on Jan 12, 2021
Latest Version
1.0.3
Package Id
use-element-in-view@1.0.3
Unpacked Size
56.35 kB
Size
10.42 kB
File Count
13
NPM Version
6.13.4
Node Version
12.16.1
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
A simple React hook to track whether an element is visible in the viewport with the Intersection Observer. This API provides a native way to asynchronously observe changes in the intersection of a target element with an ancestor element or with a top-level document's viewport.
Browser support for the Intersection Observer is incredibly wide, you can view the full list here. However, if you need to support older browsers, you can add a polyfill from here.
💡 Note: Since this module uses React Hooks, you'll need to have version >=16.8.0 of react and react-dom installed in your project
1npm install use-element-in-view --save-dev 2# or 3yarn add use-element-in-view --dev
1import React from 'react'; 2import { useElementInView } from 'use-element-in-view'; 3 4function App() { 5 const { inView, assignRef } = useElementInView(); 6 7 return <div ref={assignRef}>In View? {inView}</div>; 8}
1import React, { useRef } from 'react'; 2import { useElementInView } from 'use-element-in-view'; 3 4function App() { 5 const ref = useRef<HTMLDivElement>(null); 6 const { inView } = useElementInView({ ref }); 7 8 return <div ref={ref}>In View? {inView}</div>; 9}
You can view more examples on CodeSandbox (coming soon).
useElementInView(options)
1function useElementInView<T extends HTMLElement = HTMLElement>( 2 options?: IElementInViewOptions<T> = {} 3): IElementInViewResult<T>;
IElementInViewOptions<T>
root
, rootMargin
and threshold
are specific to the native Intersection Observer API and are forwarded along, more information can be found hereArgument | Type | Default value | Description |
---|---|---|---|
ref | T | RefObject<T> | null | null | Pass in your own ref instead of using the ref callback provided. This can be useful if you already have a ref inside your component you want to observe. |
defaultInView | boolean | false | Set the default value for the inView property. |
disconnectOnceVisible | boolean | false | Will disconnect the observer once the observed element has entered the viewport. A use-case for this is for lazy-loading images. |
onChange | (entry: IntersectionObserverEntry) => void | undefined | Provide a callback that receives the full IntersectionObserverEntry as an argument that fires on each change of element intersection. |
root | Element | null | null | The Element or Document whose bounds are used as the bounding box when testing for intersection. If no root value was passed to the constructor or its value is null, the top-level document's viewport is used |
rootMargin | string | '0px' | A string which specifies a set of offsets to add to the root's bounding box when calculating intersections, effectively shrinking or growing the root for calculation purposes. The syntax is approximately the same as that for the CSS margin property. The default is "0px 0px 0px 0px" . |
threshold | number | number[] | 0 | A list of thresholds, sorted in increasing numeric order, where each threshold is a ratio of intersection area to bounding box area of an observed target. Notifications for a target are generated when any of the thresholds are crossed for that target. If no value was passed to the constructor, 0 is used. |
IElementInViewResult<T>
Argument | Type | Description |
---|---|---|
inView | boolean | Value representing if the observed element is visible in the viewport or not. |
entry | IntersectionObserverEntry | undefined | The full entry (IntersectionObserverEntry ) returned from the Intersection Observer callback when invoked. |
assignRef | RefCallback<T> | A callback ref to be assigned to your element. Note, if you do not pass in your own ref, this must be added to the element you wish to observe. |
disconnect | () => void | Function that will disconnect the current observer instance shall you need to trigger this yourself. |
You can report bugs and issues here.
Pull-requests are more than welcome if you feel like you can improve or fix something 💥
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
35 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
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 More