ZeeCoder / use-resize-observer

A React hook that allows you to use a ResizeObserver to measure an element's size.
MIT License
651 stars 42 forks source link

allow the usage of a custom resize observer class #66

Closed javiergonzalezGenially closed 3 years ago

javiergonzalezGenially commented 3 years ago

I'd like to inject a polyfill when window.ResizeObserver is not available. By adding a customResizeObserver optional option I could do:

{
  ...
  customResizeObserver: window.ResizeObserver || resizeObserverPolyfill
}

This PR does that.

ZeeCoder commented 3 years ago

You can simply polyfill your environment prior to including your app code, or do it within your bundler. See the rollup config I use to create a polyfilled version here.

The quickest solution could also be making a module like this:

import useResizeObserver from 'use-resize-observer';
import resizeObserverPolyfill from 'some-resize-observer-polyfill';

if (!window.ResizeObserver) {
    window.ResizeObserver = resizeObserverPolyfill;
}

export default useResizeObserver;
github-actions[bot] commented 3 years ago

:tada: This issue has been resolved in version 8.0.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: