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.
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.
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.
useMeasure) is clean and fits modern functional components.<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.
ResizeAware 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).
withSize.size props into the wrapped component.// 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);
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.
// react-measure: Uses ResizeObserver internally
// No extra config needed, optimized by default
const [ref, measurements] = useMeasure();
react-resize-aware typically uses a sensor element.
// react-resize-aware: Sensor-based detection
// Wraps children with a sensor div internally
<ResizeAware>{/* content */}</ResizeAware>
react-sizeme supports multiple strategies.
ResizeObserver or window events.// react-sizeme: Configurable strategy
export default withSize({
refreshRate: 16,
allowPlaceholder: true
})(Box);
When choosing a utility library, long-term support is critical. React evolves quickly, and libraries must keep up.
react-measure is actively maintained.
react-resize-aware has limited activity.
react-sizeme is in maintenance mode.
react-measure or native hooks when possible.You need to render a chart that redraws whenever its container resizes.
react-measureResizeObserver 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>
);
}
You are maintaining a large codebase with class components that need size data.
react-sizeme (if already present) or react-measurereact-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);
You need basic dimensions for a small tooltip component.
react-resize-aware// react-resize-aware
<ResizeAware>
{({ width }) => <Tooltip width={width} />}
</ResizeAware>
| Feature | react-measure | react-resize-aware | react-sizeme |
|---|---|---|---|
| Primary API | Hooks & Render Props | Component Wrapper | Higher-Order Component |
| Detection | ResizeObserver | Sensor Element | Configurable (Observer/Window) |
| Maintenance | Active | Low Activity | Maintenance Mode |
| React Version | Modern (16.8+) | Compatible | Legacy/Modern |
| Recommendation | β Preferred | β οΈ Use with Care | β Avoid for New Projects |
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();
}, []);
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.
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.
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.
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.
It does one thing, it does it well: listens to resize events on any HTML element.
react-resize-aware is a zero dependency, ~600 bytes React Hook you can use to detect resize events without relying on intervals, loops, DOM manipulation detection or CSS redraws.
It takes advantage of the resize event on the HTMLObjectElement, works on any browser I know of, and it's super lightweight.
In addition, it doesn't directly alters the DOM, everything is handled by React.
Looking for the 2.0 docs? Click here
yarn add react-resize-aware
or with npm:
npm install --save react-resize-aware
The API is simple yet powerful, the useResizeAware Hook
returns a React node you will place inside the measured element, and an object containing its sizes:
import React from "react";
import useResizeAware from "react-resize-aware";
const App = () => {
const [resizeListener, sizes] = useResizeAware();
return (
<div style={{ position: "relative" }}>
{resizeListener}
Your content here. (div sizes are {sizes?.width} x {sizes?.height})
</div>
);
};
Heads up!: Make sure to assign a
position != initialto the HTMLElement you want to target (relative,absolute, orfixedwill work).
The Hook returns an array with two elements inside:
[resizeListener, ...] (first element)This is an invisible React node that must be placed as direct-child of the HTMLElement you want to listen the resize events of.
The node is not going to interfer with your layouts, I promise.
[..., sizes] (second element)This object contains the width and height properties, it could be null if the element is not yet rendered.
reporterYou can customize the properties of the sizes object by passing a custom reporter function as first argument of useResizeAware.
const customReporter = (target: ?HTMLIFrameElement) => ({
clientWidth: target != null ? target.clientWidth : 0,
});
const [resizeListener, sizes] = useResizeAware(customReporter);
return (
<div style={{ position: "relative" }}>
{resizeListener}
Your content here. (div clientWidth is {sizes.clientWidth})
</div>
);
The above example will report the clientWidth rather than the default offsetWidth and offsetHeight.
For completeness, below you can find an example to show how to make your code react to size variations using React Hooks:
const App = () => {
const [resizeListener, sizes] = useResizeAware();
React.useEffect(() => {
console.log("Do something with the new size values");
}, [sizes.width, sizes.height]);
return (
<div style={{ position: "relative" }}>
{resizeListener}
Your content here.
</div>
);
};