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.54kb pre-gzipped** with all dependencies.
12
+
- extremely lightweight and dependency-free; **2.59kb 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
15
- 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*
25
26
26
27
```
28
+
import React from 'react'
27
29
import useViewportSizes from 'use-viewport-sizes'
28
30
29
31
function MyComponent (props) {
@@ -38,6 +40,7 @@ function MyComponent (props) {
38
40
*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
39
41
expensive to re-render during window resize dragging.*
40
42
```
43
+
import React from 'react'
41
44
import useViewportSizes from 'use-viewport-sizes'
42
45
43
46
function MyExpensivelyRenderedComponent (props) {
@@ -47,3 +50,25 @@ function MyExpensivelyRenderedComponent (props) {
47
50
}
48
51
```
49
52
53
+
### **Server Side Rendering**
54
+
55
+
*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/).*
56
+
57
+
*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*
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.10",
3
+
"version": "0.2.0",
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