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 viewport size in your components w/ an optional debounce for updates for optimal rendering.
4
6
5
7
## Installation ##
6
8
7
9
```
8
10
npm install -D use-viewport-sizes
9
11
```
10
12
11
-
## Benefits
12
-
- extremely lightweight and dependency-free -- **2.25kb with no gzip compression**
13
+
## Benefits ##
14
+
- extremely lightweight and dependency-free -- **2.25kb** before gzipping.
13
15
- only one `window.onresize` handler used to subscribe to any changes in an unlimited number of components.
14
16
- 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
17
- debouncing does not create new handlers or waste re-renders in your component; the results are also pooled from only one resize result.
*registers dimension changes on every resize event immediately*
26
28
27
-
```
29
+
```js
28
30
importReactfrom'react'
29
31
importuseViewportSizesfrom'use-viewport-sizes'
30
32
@@ -39,7 +41,7 @@ function MyComponent (props) {
39
41
### **With Debouncing**
40
42
*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
41
43
expensive to re-render during window resize dragging.*
42
-
```
44
+
```js
43
45
importReactfrom'react'
44
46
importuseViewportSizesfrom'use-viewport-sizes'
45
47
@@ -56,7 +58,7 @@ function MyExpensivelyRenderedComponent (props) {
56
58
57
59
*Sidenote that you will see a `useLayoutEffect` warning from React. This is perfectly normal as there is no viewport/context to paint to when pre-rendering in SSR and will not interfere with your app once served to the client*
58
60
59
-
```
61
+
```js
60
62
importReact, { useLayoutEffect } from'react'
61
63
importuseViewportSizesfrom'use-viewport-sizes'
62
64
@@ -71,4 +73,14 @@ function MySSRComponent (props) {
71
73
72
74
...renderLogic
73
75
}
74
-
```
76
+
```
77
+
78
+
## Support
79
+
If you have read the examples and have any issues which you know are glitches,or would like to request something changed, please feel free to [post an issue on Github](https://github.com/rob2d/use-viewport-sizes/issues/new).
80
+
81
+
Otherwise, if this was useful and you'd like to show your support, no donations necessary, but please consider [checking out the repo](https://github.com/rob2d/use-viewport-sizes) and giving a star.
82
+
83
+
## License ##
84
+
85
+
- Open Source **[MIT license](http://opensource.org/licenses/mit-license.php)**
Copy file name to clipboardExpand all lines: package.json
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
{
2
2
"name": "use-viewport-sizes",
3
-
"version": "0.2.5",
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.",
3
+
"version": "0.2.6",
4
+
"description": "tiny React hook for tracking visible window viewport size in your components w/ an optional debounce for optimal rendering.",
0 commit comments