Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

resize-observer

> 前端框架
Open source

React ResizeObserver wrapper with render-prop and batch collection support.

200 stars0 likes2 views
WebsiteGitHub

About

React ResizeObserver wrapper with render-prop and batch collection support.

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 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScriptant-designantdjavascriptreact

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category前端框架
PricingOpen source

> Related tools

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