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 passing a ref in #16

Closed ZeeCoder closed 4 years ago

ZeeCoder commented 5 years ago

One might have more than one hooks that need to operate on the same ref. In cases like that, it would be beneficial to allow passing an existing ref in, instead of this hook taking responsibility of creating one.

Pattern could be:

const [ref, width, height] = useResizeObserver();
// vs
const [width, height] = useResizeObserver({ ref });

Need more thought and research on best practices on the topic.