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

Offering throttled- and debounced variants #53

Closed ZeeCoder closed 3 years ago

ZeeCoder commented 3 years ago

Instead of having them as options, I think it would be better to ship composing hooks, basically as they are outlined in the readme already:

This would allow me to keep the base interface minimalistic, while at the same time offer solutions to a seemingly frequent use case.

This is how it would look I think:

import useResizeObserver from 'use-resize-observer/throttled';
import useResizeObserver from 'use-resize-observer/debounced';

// Where the API / options are the exact same.

The only downside that I would probably have to provide polyfilled builds as well, so maybe:

import useResizeObserver from 'use-resize-observer/throttled/polyfilled';
import useResizeObserver from 'use-resize-observer/debounced/polyfilled';

And of course I would have to run the whole test suite and more on these builds.

I'll just leave this issue here to assess demand.