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
- extremely lightweight and dependency-free -- **2.25kb** before gzipping.
15
-
- only one `window.onresize` handler used to subscribe to any changes in an unlimited number of components.
14
+
- extremely lightweight and dependency-free -- **3.75kb**without/before gzipping.
15
+
- only one `window.onresize` handler used to subscribe to any changes in an unlimited number of components as well despite several different paradigms that pull from this.
16
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.
17
17
- debouncing does not create new handlers or waste re-renders in your component; the results are also pooled from only one resize result.
18
-
- supports SSR.
18
+
- optional hash function to update component subtree only at points you would like to.
*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
49
-
expensive to re-render during window resize dragging.*
49
+
### **With Debouncing**
50
+
51
+
If passed a number as the first argument, it registers dimension changes only when a user stops dragging/resizing the window for a specified number of miliseconds. This is useful for listening to expensive components such as data grids which may be too
52
+
expensive to re-render during window resize dragging.
50
53
```js
51
54
importReactfrom'react'
52
55
importuseViewportSizesfrom'use-viewport-sizes'
@@ -58,7 +61,38 @@ function MyExpensivelyRenderedComponent (props) {
58
61
}
59
62
```
60
63
61
-
### **Server Side Rendering**
64
+
### **Only update vpW/vpH passed on specific conditions**
65
+
If passed a function as the first argument, it will use this to calculate a hash that only updates the viewport when the calculation changes. In the example here, we are using it to detect when we have a breakpoint change which may change how a component is rendered if this is not fully possible or inconvenient via CSS `@media` queries. The hash will also be available as the 3rd value returned from the hook for convenience.
// and add new update for vpW, vpH in this component's
90
+
// subtree only when a named breakpoint changes
91
+
}
92
+
```
93
+
94
+
95
+
### **Server Side Rendering**
62
96
63
97
*While serverside rendering is supported, it requires an explicit update via `useEffect` since viewport does not actually exist on the server before rendering to client. The following has been tested with [NextJS](https://nextjs.org/).*
64
98
@@ -82,11 +116,10 @@ function MySSRComponent (props) {
82
116
```
83
117
84
118
## Support
85
-
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).
119
+
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).
86
120
87
-
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.
121
+
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 it a star (⭐).
88
122
89
123
## License ##
90
124
91
-
- Open Source **[MIT license](http://opensource.org/licenses/mit-license.php)**
0 commit comments