Gathering detailed insights and metrics for @react-hook/resize-observer
Gathering detailed insights and metrics for @react-hook/resize-observer
Gathering detailed insights and metrics for @react-hook/resize-observer
Gathering detailed insights and metrics for @react-hook/resize-observer
use-resize-observer
A React hook that allows you to use a ResizeObserver to measure an element's size.
react-resize-observer-hook
ResizeObserver + React hooks
use-measure
It's just a React hook for resize-observer, uses resize-observer-polyfill. Inspired by [react-measure](https://github.com/souporserious/react-measure)
react-cool-dimensions
React hook to measure an element's size and handle responsive components.
↩ Strongly typed, concurrent mode-safe React hooks
npm install @react-hook/resize-observer
Typescript
Module System
Node Version
NPM Version
97.8
Supply Chain
99
Quality
76.8
Maintenance
100
Vulnerability
100
License
TypeScript (85.29%)
JavaScript (14.55%)
Shell (0.17%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
1,514 Stars
429 Commits
96 Forks
9 Watchers
14 Branches
27 Contributors
Updated on Jul 09, 2025
Latest Version
2.0.2
Package Id
@react-hook/resize-observer@2.0.2
Unpacked Size
56.43 kB
Size
11.71 kB
File Count
16
NPM Version
9.6.7
Node Version
18.17.0
Published on
Jul 30, 2024
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
2
1
20
npm i @react-hook/resize-observer
A React hook that fires a callback whenever ResizeObserver detects a change to its size.
ResizeObserver
for tracking all elements used by the hooks.
This approach is astoundingly more performant
than using a ResizeObserver
per element which most hook implementations do.useCallback()
because any mutations
are handled by the hook.Check out an example on CodeSandbox
1import * as React from 'react'
2import useResizeObserver from '@react-hook/resize-observer'
3
4const useSize = (target) => {
5 const [size, setSize] = React.useState()
6
7 React.useLayoutEffect(() => {
8 setSize(target.current.getBoundingClientRect())
9 }, [target])
10
11 // Where the magic happens
12 useResizeObserver(target, (entry) => setSize(entry.contentRect))
13 return size
14}
15
16const App = () => {
17 const target = React.useRef(null)
18 const size = useSize(target)
19 return (
20 <pre ref={target}>
21 {JSON.stringify({width: size.width, height: size.height}, null, 2)}
22 </pre>
23 )
24}
1function useResizeObserver<T extends Element>( 2 target: React.RefObject<T> | React.ForwardedRef<T> | T | null, 3 callback: UseResizeObserverCallback, 4 options?: UseResizeObserverOptions 5): ResizeObserver
Argument | Type | Required? | Description |
---|---|---|---|
target | React.RefObject | Yes | A React ref created by useRef() or an HTML element |
callback | UseResizeObserverCallback | Yes | Invoked with a single ResizeObserverEntry any time the target resizes |
options | UseResizeObserverOptions | No | Options for the ResizeObserver instance. |
1export type UseResizeObserverCallback = ( 2 entry: ResizeObserverEntry, 3 observer: ResizeObserver 4) => any
1export type UseResizeObserverOptions = { 2 polyfill?: any 3}
polyfill
A ResizeObserver
polyfill implementation such as @juggle/resize-observer
(this was the default in V1.x).
1import useResizeObserver from '@react-hook/resize-observer' 2import {ResizeObserver} from '@juggle/resize-observer' 3 4useResizeObserver(..., ..., { polyfill: ResizeObserver })
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 14/28 approved changesets -- score normalized to 5
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
Reason
branch protection not enabled on development/release branches
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
37 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