Installations
npm install @envato/react-resize-observer-hook
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
14.17.0
NPM Version
8.0.0
Score
69.1
Supply Chain
90.2
Quality
75.8
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
envato
Download Statistics
Total Downloads
188,593
Last Day
12
Last Week
391
Last Month
1,870
Last Year
17,332
GitHub Statistics
MIT License
8 Stars
101 Commits
1 Forks
33 Watchers
1 Branches
242 Contributors
Updated on Jul 12, 2022
Package Meta Information
Latest Version
1.3.0
Package Id
@envato/react-resize-observer-hook@1.3.0
Unpacked Size
64.76 kB
Size
38.64 kB
File Count
43
NPM Version
8.0.0
Node Version
14.17.0
Total Downloads
Cumulative downloads
Total Downloads
188,593
Last Day
20%
12
Compared to previous day
Last Week
-4.2%
391
Compared to previous week
Last Month
40.5%
1,870
Compared to previous month
Last Year
-73.9%
17,332
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
React ResizeObserver Hook
Observe multiple DOM elements with a single ResizeObserver.
This package provides you with:
- a context
<Provider>
with aResizeObserver
instance; - a
useResizeObserver()
hook to observe any element's size changes.
This allows you to know the size of each observed element.
📚 Docs
This package was developed and documented as part of the @envato/react-breakpoints
package. It's separated into its own package because I believe it can be used separately if you don't need all the abstractions that React Breakpoints gives you. Please refer to the React Breakpoints API Docs for more details about <Provider>
and useResizeObserver()
.
⚡️ Quick start
1npm install @envato/react-resize-observer-hook
Set up the provider
1import { Provider as ResizeObserverProvider } from '@envato/react-resize-observer-hook'; 2 3const App = () => <ResizeObserverProvider>...</ResizeObserverProvider>;
⚠️ Caution — You may need to pass some props to <Provider>
to increase browser support. Please refer to the React Breakpoints API Docs.
Observe an element
1import { useResizeObserver } from '@envato/react-resize-observer-hook'; 2 3const ObservedDiv = () => { 4 const [ref, observedEntry] = useResizeObserver(); 5 const { width, height } = observedEntry.contentRect; 6 7 return ( 8 <div ref={ref}> 9 This element is {width}px wide and {height}px high. 10 </div> 11 ); 12};
Depending on your implementation of ResizeObserver
, the internal ResizeObserverEntry
can contain size information about multiple "boxes" of the observed element. Observing these boxes instead of contentRect
(default) can be done by passing an options object to the hook:
1const options = { 2 box: 'border-box' 3}; 4 5const [ref, observedEntry] = useResizeObserver(options); 6 7const width = observedEntry.borderBox[0].inlineSize; 8const height = observedEntry.borderBox[0].blockSize;
See MDN reference guide for further information.
Maintainers
- Marc Dingena (owner)
Contributing
For bug fixes, documentation changes, and small features:
- Fork this repository.
- Create your feature branch (git checkout -b my-new-feature).
- Commit your changes (git commit -am 'Add some feature').
- Push to the branch (git push origin my-new-feature).
- Create a new Pull Request.
For larger new features: Do everything as above, but first also make contact with the project maintainers to be sure your change fits with the project direction and you won't be wasting effort going in the wrong direction.

No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 0/16 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 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
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 18 are checked with a SAST tool
Score
3
/10
Last Scanned on 2025-02-10
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