Question regarding environments missing ResizeObserver
See original GitHub issueI have a library where I don’t necessarily want to polyfill ResizeObserver if a device is missing support, meaning I’d like to avoid calling useResizeObserver when ResizeObserver does not exist in DOM.
Due to React semantics, I can’t make the call to the hook conditional.
Would it be reasonable to extend the hook with an option to disable resize detection when it isn’t supported (e.g. by blocking calls to new ResizeObserver
internally)?
I know that I can add the hook to a conditionally rendered element in order to prevent it from running if ResizeObserver isn’t in DOM, e.g.:
{ ("ResizeObserver" in window) && <SomeComponentWithResizeObserver callback={setSomeStateOnResize} /> }
However, if my library only exports a hook and no component, that wouldn’t be possible.
I can create a PR if this sounds reasonable.
Issue Analytics
- State:
- Created 10 months ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Issues · ZeeCoder/use-resize-observer - GitHub
A React hook that allows you to use a ResizeObserver to measure an ... Question regarding environments missing ResizeObserver to-document.
Read more >How to mock ResizeObserver to work in unit tests using react ...
My problem is that when I go to run my units test it breaks all my tests and looking at the snapshot it...
Read more >What is the resize observer API in web API? - Educative.io
The Resize Observer API provides a way to notify an observer if an element it is registered on is re-sized in any way....
Read more >I just upgraded our lab environment to version 11.3.6. After ...
I received the error message inside Tableau Public when I connected to the MicroStrategy For Tableau Connector web URL. I receive no error ......
Read more >Responsive Components: a Solution to the Container Queries ...
If you're a web developer, you've probably heard about container queries ... will apply no matter what environment the component is within.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I just used
delete
in order to quickly test what happens in an environment where ResizeObserver is missing and calling it would throw an error. Setting ref tonull
prevents calls to ResizeObserver. Thatdelete
is not part of my actual code 😬Real code example would be something like:
Great, I’ll leave this issue open until it’s documented, I think it’s an interesting use-case. @martinstark can you just also confirm when you did the implementation if there were anything else that needed to be considered, or if it was just copy-c of the above code? Just so I’d know what to document.