百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

resize-observer

> 前端框架
开源

带有渲染属性和批量收集支持的 React ResizeObserver 包装器。

200 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

带有渲染属性和批量收集支持的 React ResizeObserver 包装器。

English | 简体中文

Highlights

  • Observes resize changes for a single React child.
  • Supports render props when the observed element is not the direct child.
  • Batches multiple child resize events with ResizeObserver.Collection.
  • Reports both bounding-box and offset sizes.

Install

bash
npm install @rc-component/resize-observer

Usage

typescript
import ResizeObserver from '@rc-component/resize-observer';

export default () => (
   {
      console.log(size.width, size.height, element);
    }}
  >
    
  
);
typescript
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/

Examples

Run the local dumi site:

bash
npm install
npm start

Then open http://localhost:8000.

API

ResizeObserver

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.

SizeInfo

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.

ResizeObserver.Collection

Name Type Default Description
children ReactNode - Observers to collect.
onBatchResize (resizeInfo: ResizeInfo[]) => void - Triggered once per microtask with all collected child resize events.

Development

bash
npm install
npm start
npm test
npm run tsc
npm run compile
npm run build

The dumi site runs at http://localhost:8000 by default.

Release

bash
npm run prepublishOnly

The release flow is handled by @rc-component/np through the rc-np command after the package build.

License

@rc-component/resize-observer is released under the MIT license.

Issues· 26 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScriptant-designantdjavascriptreact

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架