Closed khusamov closed 2 years ago
Seems like the TS types will need to change from using HTMLElement
to simply Element
, as ResizeObserver
itself can observe any Element
.
:tada: This issue has been resolved in version 9.0.0 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
Thank you very much!
I checked working with SVG. Does not work. The height variable is always zero.
I checked working with SVG. Does not work. The height variable is always zero.
Could you please provide reproduction in codesandbox? it would be even better if you could check using raw ResizeObserver first, as it's known to be a bit quirky with svgs.
https://codesandbox.io/s/use-resize-observer-hsxycd?file=/src/App.tsx
It is required to display a square in the middle of the browser. But instead of the browser dimensions, the dimensions of the square are substituted in height, width.
Here's a slightly modified version of that sandbox: https://codesandbox.io/s/use-resize-observer-forked-29q3fg?file=/src/App.tsx
As you can see the hook reports the same exact values that a raw ResizeObserver reports, so I see no issues with the hook based on this example.
Why doesn't it return the dimensions of the SVG container?
Not 100% sure, the ResizeObserver spec around SVGs is a bit weird.
Here's some stuff I found, hope it helps:
Also I wonder if you could just wrap your SVG in a div and measure that instead? Might help you depending on your exact use-case.
Will there be support for SVG elements or not?
Now the error appears. Since the SVG element is not compatible with the HTML element.