Installations
npm install use-element-dimensions
Developer Guide
Typescript
Yes
Module System
CommonJS, UMD
Node Version
13.10.1
NPM Version
6.13.7
Score
67.4
Supply Chain
92.3
Quality
75.1
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (44.13%)
JavaScript (43.05%)
HTML (10.07%)
CSS (2.76%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
danielkov
Download Statistics
Total Downloads
132,633
Last Day
125
Last Week
691
Last Month
3,414
Last Year
48,294
GitHub Statistics
MIT License
6 Stars
52 Commits
2 Forks
1 Watchers
46 Branches
2 Contributors
Updated on Feb 06, 2025
Bundle Size
1.13 kB
Minified
606.00 B
Minified + Gzipped
Package Meta Information
Latest Version
2.1.3
Package Id
use-element-dimensions@2.1.3
Unpacked Size
15.88 kB
Size
4.78 kB
File Count
10
NPM Version
6.13.7
Node Version
13.10.1
Total Downloads
Cumulative downloads
Total Downloads
132,633
Last Day
-20.9%
125
Compared to previous day
Last Week
-10.6%
691
Compared to previous week
Last Month
47.3%
3,414
Compared to previous month
Last Year
67.2%
48,294
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
use-element-dimensions

React Hook to figure out DOM Element dimensions with updates
Usage
1import useDimensions from "use-element-dimensions"; 2 3const Example = () => { 4 const [{ width, height }, ref] = useDimensions(); 5 return ( 6 <div ref={ref}> 7 The width of this div is: {width} and the height is: {height} 8 </div> 9 ); 10};
API
The first item in the tuple returned by the hook includes all properties of the latest ResizeObserverEntry
for the specific element.
borderBoxSize
An object containing the new border box size of the observed element when the callback is run.
contentBoxSize
An object containing the new content box size of the observed element when the callback is run.
contentRect
A DOMRectReadOnly object containing the new size of the observed element when the callback is run. Note that this is better supported than the above two properties, but it is left over from an earlier implementation of the Resize Observer API, is still included in the spec for web compat reasons, and may be deprecated in future versions.
target
A reference to the Element or SVGElement being observed.
The DOMRect
returned by target.getBoundingClientRect
also lends its properties to this value.
x
The x coordinate of the DOMRect's origin.
y
The y coordinate of the DOMRect's origin.
width
The width of the DOMRect.
height
The height of the DOMRect.
top
Returns the top coordinate value of the DOMRect (has the same value as y, or y + height if height is negative.)
right
Returns the right coordinate value of the DOMRect (has the same value as x + width, or x if width is negative.)
bottom
Returns the bottom coordinate value of the DOMRect (has the same value as y + height, or y if height is negative.)
left
Returns the left coordinate value of the DOMRect (has the same value as x, or x + width if width is negative.)
Use case
There are already some hook libraries that provide dimensions on first render or even update them on window
resize event, however in many cases this may not be sufficient. HTML DOM Elements can resize in response to a lot of things we don't expect, only one of which is screen size, for example:
- When animating any of the size properties.
- Setting a size properties on an encapsulating DOM Node.
- Orientation change (
resize
triggers in this case - or it should).
Development
Everything in this package is in src/index.ts
. If you want to run an example to develop against, install parcel
globally and then run parcel example/simple/index.html
from the root directory of the project.
Building
Run yarn build
to build for the three targets specified.
Testing
Integration tests use Cypress, because it is hard to do unit tests for hooks and viewport resizing.
Examples
The examples live in the example
directory. To run any of them, make sure devDependencies
are installed and run yarn parcel example/<name>/index.html
.

No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/15 approved changesets -- 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 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 15 are checked with a SAST tool
Reason
60 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-x9w5-v3q2-3rhw
- Warn: Project is vulnerable to: GHSA-w8qv-6jwh-64r5
- Warn: Project is vulnerable to: GHSA-257v-vj4p-3w2h
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-r9p9-mrjm-926w
- Warn: Project is vulnerable to: GHSA-434g-2637-qmqr
- Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m
- Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw
- Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p
- Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747
- Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44
- Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-7r28-3m3f-r2pr
- Warn: Project is vulnerable to: GHSA-r8j5-h5cx-65gg
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-8hfj-j24r-96c4
- Warn: Project is vulnerable to: GHSA-wc69-rhjr-hc9g
- Warn: Project is vulnerable to: GHSA-92xj-mqp7-vmcj
- Warn: Project is vulnerable to: GHSA-wxgw-qj99-44c2
- Warn: Project is vulnerable to: GHSA-5rrq-pxf6-6jx5
- Warn: Project is vulnerable to: GHSA-8fr3-hfg3-gpgp
- Warn: Project is vulnerable to: GHSA-gf8q-jrpm-jvxq
- Warn: Project is vulnerable to: GHSA-2r2c-g63r-vccr
- Warn: Project is vulnerable to: GHSA-cfm4-qjh2-4765
- Warn: Project is vulnerable to: GHSA-x4jg-mjrx-434g
- Warn: Project is vulnerable to: GHSA-rp65-9cf3-cjxr
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-566m-qj78-rww5
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-hwj9-h5mp-3pm3
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
- Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p
- Warn: Project is vulnerable to: GHSA-4rq4-32rv-6wp6
- Warn: Project is vulnerable to: GHSA-64g7-mvw6-v9qj
- Warn: Project is vulnerable to: GHSA-4wf5-vphf-c2xc
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-7p7h-4mm5-852v
- Warn: Project is vulnerable to: GHSA-38fc-wpqx-33j7
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
Score
1.7
/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 MoreOther packages similar to use-element-dimensions
@nextui-org/use-measure
Hook that measure and track a element dimensions
@heroui/use-measure
Hook that measure and track a element dimensions
@nextui-org/use-real-shape
Hook that returns the real dimensions of an element
@custom-react-hooks/use-element-size
`useElementSize` is a React hook that enables dynamic tracking of an HTML element's dimensions. It updates the element's width and height in response to window resizing, element mounting/unmounting, and ref changes.