react-measure vs react-resize-aware vs react-sizeme
Measuring Component Dimensions in React
react-measurereact-resize-awarereact-sizemeSimilar Packages:

Measuring Component Dimensions in React

react-measure, react-resize-aware, and react-sizeme are React utilities designed to track DOM element dimensions (width, height, position) and trigger re-renders when those dimensions change. They abstract the complexity of listening to resize events or using the ResizeObserver API directly. react-measure is the most feature-rich, offering both render props and hooks with support for various measurement types. react-sizeme is a classic Higher-Order Component (HOC) solution, now in maintenance mode, often found in legacy codebases. react-resize-aware provides a component-based approach focused on simplicity. All three solve the same core problem but differ significantly in API design, maintenance status, and underlying implementation strategies.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
react-measure01,941-306 years agoMIT
react-resize-aware057032 kB15 months agoMIT
react-sizeme01,962-345 years agoMIT

React Dimension Libraries: react-measure vs react-resize-aware vs react-sizeme

Building responsive React components often requires knowing the exact size of a DOM element. While CSS handles most layout needs, JavaScript measurements are necessary for dynamic behaviors like canvas rendering, custom tooltips, or complex grid calculations. react-measure, react-resize-aware, and react-sizeme all solve this problem, but they use different patterns and vary in long-term viability.

šŸ—ļø API Patterns: Hooks, Render Props, and HOCs

The biggest difference between these libraries is how they integrate into your component tree. This affects code readability and refactoring ease.

react-measure supports both Render Props and Hooks.

  • The Hook API (useMeasure) is clean and fits modern functional components.
  • The Component API (<Measure>) works well for older class components or specific render prop needs.
// react-measure: Hook API
import { useMeasure } from 'react-measure';

function Box() {
  const [ref, { width, height }] = useMeasure();
  return <div ref={ref}>Width: {width}, Height: {height}</div>;
}

react-resize-aware uses a Component wrapper approach.

  • You wrap your target content inside the ResizeAware component.
  • It passes size props to the child function or component.
// react-resize-aware: Component Wrapper
import ResizeAware from 'react-resize-aware';

function Box() {
  return (
    <ResizeAware>
      {({ width, height }) => (
        <div>Width: {width}, Height: {height}</div>
      )}
    </ResizeAware>
  );
}

react-sizeme relies on a Higher-Order Component (HOC).

  • You wrap your component definition with withSize.
  • This injects size props into the wrapped component.
  • This pattern is older and can make component trees harder to debug in DevTools.
// react-sizeme: HOC Pattern
import { withSize } from 'react-sizeme';

function Box({ size: { width, height } }) {
  return <div>Width: {width}, Height: {height}</div>;
}

export default withSize()(Box);

āš™ļø Under the Hood: ResizeObserver vs Window Events

Performance depends on how the library detects changes. Modern browsers offer ResizeObserver, which is efficient and element-specific. Older methods rely on window resize events or iframe hacks.

react-measure prioritizes ResizeObserver.

  • It detects changes to the specific element, not the whole window.
  • This reduces unnecessary calculations during unrelated layout shifts.
  • It falls back gracefully if the API is unavailable.
// react-measure: Uses ResizeObserver internally
// No extra config needed, optimized by default
const [ref, measurements] = useMeasure(); 

react-resize-aware typically uses a sensor element.

  • It often injects a hidden element to detect size changes.
  • This can be slightly heavier than a native observer but works across older browsers.
// react-resize-aware: Sensor-based detection
// Wraps children with a sensor div internally
<ResizeAware>{/* content */}</ResizeAware>

react-sizeme supports multiple strategies.

  • You can configure it to use ResizeObserver or window events.
  • Requires explicit configuration to get the best performance.
// react-sizeme: Configurable strategy
export default withSize({ 
  refreshRate: 16, 
  allowPlaceholder: true 
})(Box);

āš ļø Maintenance and Future Proofing

When choosing a utility library, long-term support is critical. React evolves quickly, and libraries must keep up.

react-measure is actively maintained.

  • It receives updates to support newer React versions.
  • The community adoption is high, meaning bugs are found and fixed faster.
  • It is the safest bet for new projects among the three.

react-resize-aware has limited activity.

  • Updates are infrequent.
  • It works for simple cases but may lag behind React best practices.
  • Use with caution in large-scale enterprise applications.

react-sizeme is in maintenance mode.

  • The repository indicates it is no longer actively developed.
  • It relies on the HOC pattern, which is less favored in modern React.
  • Do not use for new projects. Migrate existing usage to react-measure or native hooks when possible.

🧩 Real-World Implementation Scenarios

Scenario 1: Dynamic Chart Container

You need to render a chart that redraws whenever its container resizes.

  • āœ… Best choice: react-measure
  • Why? The Hook API keeps the chart logic contained, and ResizeObserver ensures high-frequency updates don't slow down the UI.
// react-measure
function ChartContainer() {
  const [ref, { width, height }] = useMeasure();
  return (
    <div ref={ref}>
      <MyChart width={width} height={height} />
    </div>
  );
}

Scenario 2: Legacy Class Component

You are maintaining a large codebase with class components that need size data.

  • āœ… Best choice: react-sizeme (if already present) or react-measure
  • Why? react-sizeme HOC wraps class components easily without refactoring to hooks. However, react-measure render props also work well here.
// react-sizeme
class Dashboard extends React.Component {
  render() {
    const { width } = this.props.size;
    return <div>{width}</div>;
  }
}
export default withSize()(Dashboard);

Scenario 3: Simple Tooltip Positioning

You need basic dimensions for a small tooltip component.

  • āœ… Best choice: react-resize-aware
  • Why? If you want a quick wrapper without importing hooks or configuring HOCs, this component-based approach is straightforward.
// react-resize-aware
<ResizeAware>
  {({ width }) => <Tooltip width={width} />}
</ResizeAware>

šŸ“Š Summary Comparison

Featurereact-measurereact-resize-awarereact-sizeme
Primary APIHooks & Render PropsComponent WrapperHigher-Order Component
DetectionResizeObserverSensor ElementConfigurable (Observer/Window)
MaintenanceActiveLow ActivityMaintenance Mode
React VersionModern (16.8+)CompatibleLegacy/Modern
Recommendationāœ… Preferredāš ļø Use with CareāŒ Avoid for New Projects

šŸ’” The Modern Alternative: Native ResizeObserver

Before installing any package, consider if you need one at all. Modern React applications can use the ResizeObserver API directly via a custom hook or a lightweight library like @react-hook/resize-observer.

// Native approach (no extra library)
useEffect(() => {
  const observer = new ResizeObserver(entries => {
    for (let entry of entries) {
      console.log(entry.contentRect.width);
    }
  });
  if (ref.current) observer.observe(ref.current);
  return () => observer.disconnect();
}, []);

šŸ’” Final Recommendation

react-measure is the clear winner for most teams today. It balances feature depth with modern API design. The Hook support makes it easy to test and compose, while the active maintenance ensures it won't break with future React updates.

react-sizeme should be treated as legacy technology. If you encounter it in an existing codebase, plan to migrate away from it during major refactors. Its HOC pattern adds unnecessary abstraction compared to Hooks.

react-resize-aware sits in the middle. It is simple but lacks the ecosystem support of react-measure. Only choose it if you have a specific constraint preventing the use of Hooks or if you need a very specific component-wrapper behavior not offered elsewhere.

Final Thought: For new architecture, prioritize react-measure or native ResizeObserver hooks. Avoid locking your project into maintenance-mode libraries like react-sizeme unless you are strictly bound by legacy constraints.

How to Choose: react-measure vs react-resize-aware vs react-sizeme

  • react-measure:

    Choose react-measure for new projects requiring robust dimension tracking with modern React patterns. It supports both Hooks and Render Props, making it flexible for functional and class components. It actively leverages ResizeObserver for performance, making it suitable for complex layouts where frequent measurements occur without causing layout thrashing.

  • react-resize-aware:

    Choose react-resize-aware if you need a lightweight, component-based solution and prefer avoiding Hooks or HOCs. It is suitable for simpler use cases where you just need to wrap a component and access size props. However, verify its maintenance status for long-term projects, as it has a smaller ecosystem compared to react-measure.

  • react-sizeme:

    Choose react-sizeme only for maintaining existing legacy applications that already rely on its Higher-Order Component pattern. It is not recommended for new development as it is in maintenance mode. If you are starting fresh, prefer react-measure or native ResizeObserver hooks to ensure long-term support and better alignment with modern React practices.

README for react-measure

šŸ“ React Measure

npm version Dependency Status

Compute measurements of React components. Uses a ResizeObserver to detect when an element's dimensions have changed.

Includes a polyfill for ResizeObserver in unsupported browsers.

Install

yarn add react-measure

npm install react-measure --save

<script src="https://unpkg.com/react-measure/dist/index.umd.js"></script>
(UMD library exposed as `ReactMeasure`)

Measure Component

Wrap any child component and calculate its client rect.

Props

client: PropTypes.bool

Adds the following to contentRect.client returned in the child function.

clientTop, clientLeft, clientWidth, and clientHeight.

offset: PropTypes.bool

Adds the following to contentRect.offset returned in the child function.

offsetTop, offsetLeft, offsetWidth, and offsetHeight.

scroll: PropTypes.bool

Adds the following to contentRect.scroll returned in the child function.

scrollTop, scrollLeft, scrollWidth, and scrollHeight.

bounds: PropTypes.bool

Uses getBoundingClientRect to calculate the element rect and add it to contentRect.bounds returned in the child function.

margin: PropTypes.bool

Uses getComputedStyle to calculate margins and add it to contentRect.margin returned in the child function.

innerRef: PropTypes.func

Use this to access the internal component ref.

onResize: PropTypes.func

Callback invoked when either element width or height have changed. Note that this will be called twice on mount to get the initial values. The first call will come from componentDidMount while the second call will come from the ResizeObserver.

children: PropTypes.func

Children must be a function. Will receive the following object shape:

  • measureRef: must be passed down to your component's ref in order to obtain a proper node to measure

  • measure: use to programmatically measure your component, calls the internal measure method in withContentRect

  • contentRect: this will contain any of the following allowed rects from above: client, offset, scroll, bounds, or margin. It will also include entry from the ResizeObserver when available.

Example

import Measure from 'react-measure'
import classNames from 'classnames'

class ItemToMeasure extends Component {
  state = {
    dimensions: {
      width: -1,
      height: -1,
    },
  }

  render() {
    const { width, height } = this.state.dimensions
    const className = classNames(width < 400 && 'small-width-modifier')

    return (
      <Measure
        bounds
        onResize={contentRect => {
          this.setState({ dimensions: contentRect.bounds })
        }}
      >
        {({ measureRef }) => (
          <div ref={measureRef} className={className}>
            I can do cool things with my dimensions now :D
            {height > 250 && (
              <div>Render responsive content based on the component size!</div>
            )}
          </div>
        )}
      </Measure>
    )
  }
}

withContentRect(types) HoC

A higher-order component that provides dimensions to the wrapped component. Accepts types, which determines what measurements are returned, similar to above. Then returns a function to pass the component you want measured.

Pass an array or single value of either client, offset, scroll, bounds, or margin to calculate and receive those measurements as the prop contentRect in your wrapped component. You can also use the measure function passed down to programmatically measure your component if you need to. And finally, remember to pass down the measureRef to the component you want measured.

Passes down the same props as the Measure child function above, measureRef, measure, and contentRect.

Fun fact, the Measure component is a thin wrapper around withContentRect. Just check the source. This means your wrapped component will accept the same props as Measure does 😊

Example

import { withContentRect } from 'react-measure'

const ItemToMeasure = withContentRect('bounds')(
  ({ measureRef, measure, contentRect }) => (
    <div ref={measureRef}>
      Some content here
      <pre>{JSON.stringify(contentRect, null, 2)}</pre>
    </div>
  )
)

Run Example

clone repo

git clone git@github.com:souporserious/react-measure.git

move into folder

cd ~/react-measure

install package dependencies

yarn

move into site folder and install local site dependencies

cd ~/site && yarn

run development mode

yarn gatsby develop