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
| ref | undefined | RefObject | HTMLElement | A ref or element to observe. | undefined |
49
+
| box | undefined | "border-box" | "content-box" | "device-pixel-content-box" | The [box model](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/observe#syntax) to use for observation. | "content-box" |
50
+
| onResize | undefined | ({ width?: number, height?: number }) => void | A callback receiving the element size. If given, then the hook will not return the size, and instead will call this callback. | undefined |
51
+
| round | undefined | (n: number) => number | A function to use for rounding values instead of the default. |`Math.round()`|
Note that if the browser does not support the given box type, then the hook won't report any sizes either.
90
+
91
+
### Box Options
92
+
93
+
Note that box options are experimental, and as such are not supported by all browsers that implemented ResizeObservers. (See [here](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserverEntry).)
94
+
95
+
`content-box` (default)
67
96
68
-
### Getting the raw element from the default `RefCallback`
97
+
Safe to use by all browsers that implemented ResizeObservers. The hook internally will fall back to `contentRect` from
98
+
the old spec in case `contentBoxSize` is not available.
99
+
100
+
`border-box`
101
+
102
+
Supported well for the most part by evergreen browsers. If you need to support older versions of these browsers however,
103
+
then you may want to feature-detect for support, and optionally include a polyfill instead of the native implementation.
104
+
105
+
`device-pixel-content-box`
106
+
107
+
Surma has a [very good article](https://web.dev/device-pixel-content-box/) on how this allows us to do pixel perfect
108
+
rendering. At the time of writing, however this has very limited support.
109
+
The advices on feature detection for `border-box` apply here too.
110
+
111
+
### Custom Rounding
112
+
113
+
By default this hook passes the measured values through `Math.round()`, to avoid re-rendering on every subpixel changes.
114
+
115
+
If this is not what you want, then you can provide your own function:
@@ -250,8 +329,8 @@ import useResizeObserver from "use-resize-observer/polyfilled";
250
329
251
330
Note that using the above will use the polyfill, [even if the native ResizeObserver is available](https://github.com/juggle/resize-observer#basic-usage).
252
331
253
-
To use the polyfill as a fallback instead only when the native RO is unavailable, you can polyfill yourself instead,
254
-
either in your app's entry file, or you could create a local useResizeObserver module, like so:
332
+
To use the polyfill as a fallback only when the native RO is unavailable, you can polyfill yourself instead,
333
+
either in your app's entry file, or you could create a local `useResizeObserver` module, like so:
0 commit comments