alibaba / hooks

A high-quality & reliable React Hooks library. https://ahooks.pages.dev/
https://ahooks.js.org/
MIT License
13.98k stars 2.71k forks source link

[Feature Request] useSize() `options` support #2227

Open kkimdev opened 1 year ago

kkimdev commented 1 year ago

ResizeObserver.observe() has options https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/observe , but that's not configurable from useSize() currently.

My usecase is using border-box option.

liuyib commented 1 year ago

It's a great suggestion, we'll add it in the future version.

askwuxue commented 1 year ago

It's a great suggestion, we'll add it in the future version.

ahooks relies on the resize-observer-polyfill package, but the author of resize-observer-polyfill hasn't maintained it for a long time, so it doesn't support the options parameter for observe(). I'm wondering if there's an alternative solution, such as using @juggle/resize-observer.

askwuxue commented 1 year ago

It's a great suggestion, we'll add it in the future version.

ahooks relies(依赖) on the resize-observer-polyfill package, but the author of resize-observer-polyfill hasn't maintained(保持) it for a long time, so it doesn't support the options parameter for observe(). I'm wondering if there's an alternative(替代品) solution, such as using @juggle/resize-observer.

但这是一个Break change。原因是resize-observer-polyfill这个库在计算时,是 content width + padding。

liuyib commented 1 year ago

但这是一个Break change。原因是resize-observer-polyfill这个库在计算时,是 content width + padding。

这俩个库哪个是按照规范来的呢?


我看到 @juggle/resize-observer 是按照最新的规范来的,但是其 READMD 注明了最新的规范还没完成:

image
askwuxue commented 1 year ago

但这是一个Break change。原因是resize-observer-polyfill这个库在计算时,是 content width + padding。

这俩个库哪个是按照规范来的呢?

我看到 @juggle/resize-observer 是按照最新的规范来的,但是其 READMD 注明了最新的规范还没完成: image

如果按照MDN当前定义的规范的话,@juggle/resize-observer 是符合规范来的。至少是支持options选项的。

liuyib commented 1 year ago

如果按照MDN当前定义的规范的话,@juggle/resize-observer 是符合规范来的。至少是支持options选项的。

Get! 感谢你提供的参考建议~