带有渲染属性和批量收集支持的 React ResizeObserver 包装器。
English | 简体中文
ResizeObserver.Collection.npm install @rc-component/resize-observerimport ResizeObserver from '@rc-component/resize-observer';
export default () => (
{
console.log(size.width, size.height, element);
}}
>
);import ResizeObserver from '@rc-component/resize-observer';
export default () => (
{
console.log(infoList.map(({ data, size }) => [data, size.width]));
}}
>
);Online preview: https://resize-observer.react-component.vercel.app/
Run the local dumi site:
npm install
npm startThen open http://localhost:8000.
| Name | Type | Default | Description |
|---|---|---|---|
children |
ReactNode | (ref: React.RefObject) => ReactElement |
- | Element to observe, or a render function receiving the observer ref. |
data |
any | - | Extra payload passed to ResizeObserver.Collection callbacks. |
disabled |
boolean | false | Disable resize observation. |
onResize |
(size: SizeInfo, element: HTMLElement) => void |
- | Triggered when the observed element size changes. |
| Name | Type | Description |
|---|---|---|
height |
number | Floored bounding-box height. |
offsetHeight |
number | Element offset height, normalized when it matches the rounded bounding-box height. |
offsetWidth |
number | Element offset width, normalized when it matches the rounded bounding-box width. |
width |
number | Floored bounding-box width. |
| Name | Type | Default | Description |
|---|---|---|---|
children |
ReactNode | - | Observers to collect. |
onBatchResize |
(resizeInfo: ResizeInfo[]) => void |
- | Triggered once per microtask with all collected child resize events. |
npm install
npm start
npm test
npm run tsc
npm run compile
npm run buildThe dumi site runs at http://localhost:8000 by default.
npm run prepublishOnlyThe release flow is handled by @rc-component/np through the rc-np command after the package build.
@rc-component/resize-observer is released under the MIT license.
暂无开放 Issues,或尚未同步最近议题。