ZeeCoder / use-resize-observer

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

Future enhancement to return element coordinates #107

Open ritchieanesco opened 7 months ago

ritchieanesco commented 7 months ago

Thank you for the great library!!

Just wondering if there were any plans to expose the element's x, y, top, left, etc. coordinates since you are already accessing dimensions from contentRect?

ZeeCoder commented 1 month ago

You're welcome! :pray: Hmm, maybe.

Currently onResize reports width and height, and it reports the requested kind of dimensions (content- or border box size), using borderBoxSize, contentBoxSize, or the old contentRect prop.

Only contentRect has properties other than width / height, and it seems a bit accidental if I'm honest from an early implementation, as outlined in the MDN docs.

I would rather consider a lower-level implementation to hook onto, something like onEntry reporting the entire entry object itself as an escape hatch, allowing to implement something like this. :thinking:

So basically I would keep the current useResizeObserver as-is, to preserve its size observing API and optimisations, and could just add another lower-level hook called something like useResizeObserverEntry, with an onChange method :thinking: