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 bypassing the observer #42

Closed GreenGremlin closed 4 years ago

GreenGremlin commented 4 years ago

...by not passing a ref option.

Putting up this PR early for feedback. Tests are still needed.

I would like to use use-resize-observer, without adding the polyfill. This change makes that possible by not initializing the observer, if no ref is passed.

GreenGremlin commented 4 years ago

I've added a test to assert that a ResizeObserver is not initialized, if no ref is passed.

GreenGremlin commented 4 years ago

Is there anything I can do the help get this PR merged?

ZeeCoder commented 4 years ago

Sorry I just don't have time to review things right now. Maybe sometime next week.

On Mon, 27 Jul 2020, 23:40 Jonathan Felchlin, notifications@github.com wrote:

Is there anything I can do the help get this PR merged?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ZeeCoder/use-resize-observer/pull/42#issuecomment-664652577, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA4CKEXDWTKSGWZCEHWBNUTR5XX4XANCNFSM4PEED3IQ .

GreenGremlin commented 4 years ago

@ZeeCoder I don't mean to be a pest, but is there any chance you might have some time to look at this PR any time soon?

ZeeCoder commented 4 years ago

There are a couple issues with the proposed code changes here:

I've created a new PR based on your needs. Still a WIP, but will cover your use case and have the above points addressed as well: https://github.com/ZeeCoder/use-resize-observer/pull/44

Essentially the hook would consider "null" as a special ref param, which would signal for the hook that you might pass a real ref in later for observation, but for the time being you don't need it, and so a ResizeObserver instance would not be necessary either until then.

ZeeCoder commented 4 years ago

Addressed in: https://github.com/ZeeCoder/use-resize-observer/releases/tag/v6.2.0-alpha.1