You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A tiny React hook which allows you to track visible window/document area in your components w/ an optional debounce for updates to give the most optimal experience for components with expensive renders.
3
+
tiny React hook which allows you to track visible window viewport size in your components w/ an optional debounce for updates for optimal rendering.
- extremely lightweight and dependency-free; **2.8kb pre-gzipped** with all dependencies.
13
13
- only one `window.onresize` handler used to subscribe to any changes in an unlimited number of components.
14
14
- optional debounce to delay updates until user stops dragging their window for a moment; this can make expensive components with size-dependent calculations run much faster and your app feel smoother.
15
-
- debouncing does not create new handlers; the results are pooled from only one result.
15
+
- debouncing does not create new handlers or waste re-renders in your component; the results are also pooled from only one resize result.
16
16
17
17
## Usage ##
18
18
19
-
### See it in Action ###
20
-
For an illustration of the concept, check out a CodeSandox:
19
+
### **See it in Action** ###
20
+
*for an illustration of the concept, check out a CodeSandox* @
*registers dimension changes on every resize event immediately*
25
25
26
26
```
27
27
import useViewportSizes from 'use-viewport-sizes'
28
28
29
-
function MyComponent () {
29
+
function MyComponent (props) {
30
30
const [vpWidth, vpHeight] = useViewportSizes();
31
+
32
+
...renderLogic
31
33
}
32
34
```
33
35
34
36
35
-
### With Debouncing
36
-
*for expensive components such as data grids which may be too
37
+
### **With Debouncing**
38
+
*registers dimension changes only when a user stops dragging/resizing the window for a specified number of miliseconds; for expensive components such as data grids which may be too
37
39
expensive to re-render during window resize dragging.*
Copy file name to clipboardExpand all lines: package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
{
2
2
"name": "use-viewport-sizes",
3
-
"version": "0.1.7",
3
+
"version": "0.1.8",
4
4
"description": "tiny React hook which allows you to track visible window viewport size in your components w/ an optional debounce for updates for optimal rendering.",
0 commit comments