Gathering detailed insights and metrics for @custom-react-hooks/use-element-size
Gathering detailed insights and metrics for @custom-react-hooks/use-element-size
A collection of reusable and well-documented custom React hooks for supercharging your React applications. These hooks cover a wide range of functionalities, making it easier for you to build dynamic and interactive user interfaces.
npm install @custom-react-hooks/use-element-size
Typescript
Module System
Node Version
NPM Version
70.8
Supply Chain
100
Quality
77.4
Maintenance
100
Vulnerability
100
License
TypeScript (96.96%)
JavaScript (2.56%)
Shell (0.47%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
32,557
Last Day
102
Last Week
1,275
Last Month
5,990
Last Year
31,844
MIT License
21 Stars
36 Commits
1 Forks
1 Watchers
1 Branches
1 Contributors
Updated on Feb 16, 2025
Minified
Minified + Gzipped
Latest Version
1.5.1
Package Id
@custom-react-hooks/use-element-size@1.5.1
Unpacked Size
7.55 kB
Size
3.60 kB
File Count
8
NPM Version
10.3.0
Node Version
18.17.0
Published on
Aug 18, 2024
Cumulative downloads
Total Downloads
Last Day
25.9%
102
Compared to previous day
Last Week
-15.8%
1,275
Compared to previous week
Last Month
53.3%
5,990
Compared to previous month
Last Year
4,366.2%
31,844
Compared to previous year
1
useElementSize
HookuseElementSize
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.
window
object.useLayoutEffect
for precise dimension measurements after DOM mutations.Choose and install individual hooks that suit your project needs, or install the entire collection for a full suite of utilities.
1npm install @custom-react-hooks/use-element-size
or
1yarn add @custom-react-hooks/use-element-size
1npm install @custom-react-hooks/all
or
1yarn add @custom-react-hooks/all
The useElementSize
hook must be imported using a named import as shown below:
Named Import:
1import { useElementSize } from '@custom-react-hooks/use-element-size';
This approach ensures that the hook integrates seamlessly into your project, maintaining consistency and predictability in how you use our package.
1import React, { useRef, useState } from 'react'; 2import { useElementSize } from '@custom-react-hooks/all'; 3 4const ElementSizeComponent = () => { 5 const [setRef, size] = useElementSize(); 6 7 return ( 8 <div className="element-size"> 9 <div 10 ref={setRef} 11 className="resize" 12 > 13 <p>Drag from the bottom-right corner to resize.</p> 14 </div> 15 <br /> 16 <div>Current Size:</div> 17 <div className="btns"> 18 <p> 19 Width: <span>{size.width}px</span> 20 </p> 21 <p> 22 Height: <span>{size.height}px</span> 23 </p> 24 </div> 25 </div> 26 ); 27}; 28 29export default ElementSizeComponent;
In this example, useElementSize
is used to measure and display the dimensions of a div
element.
ref
: A React ref object attached to the element whose size you want to measure.width
: width of the elementheight
: height of the element.Your contributions to improve useElementSize
are welcome. Feel free to submit issues or pull requests to the repository.
No vulnerabilities found.
No security vulnerabilities found.