Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-measure

Package Overview
Dependencies
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-measure

Compute measurements of React components.

  • 0.3.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
147K
decreased by-53.38%
Maintainers
1
Weekly downloads
 
Created

What is react-measure?

The react-measure package is a React component that allows you to measure the dimensions and position of a DOM element. It provides a declarative way to get the size and position of elements, which can be useful for responsive design, animations, and other dynamic UI behaviors.

What are react-measure's main functionalities?

Measure Dimensions

This feature allows you to measure the width and height of a DOM element. The `Measure` component wraps around the element you want to measure, and the `onResize` callback updates the state with the new dimensions whenever the element is resized.

import React from 'react';
import Measure from 'react-measure';

class MyComponent extends React.Component {
  state = {
    dimensions: {
      width: -1,
      height: -1
    }
  };

  render() {
    return (
      <Measure
        bounds
        onResize={(contentRect) => {
          this.setState({ dimensions: contentRect.bounds });
        }}
      >
        {({ measureRef }) => (
          <div ref={measureRef} style={{ width: '100%' }}>
            <p>The width of this element is {this.state.dimensions.width}px</p>
            <p>The height of this element is {this.state.dimensions.height}px</p>
          </div>
        )}
      </Measure>
    );
  }
}

export default MyComponent;

Measure Position

This feature allows you to measure the position (top and left) of a DOM element. The `Measure` component wraps around the element you want to measure, and the `onResize` callback updates the state with the new position whenever the element is resized.

import React from 'react';
import Measure from 'react-measure';

class MyComponent extends React.Component {
  state = {
    position: {
      top: -1,
      left: -1
    }
  };

  render() {
    return (
      <Measure
        bounds
        onResize={(contentRect) => {
          this.setState({ position: contentRect.bounds });
        }}
      >
        {({ measureRef }) => (
          <div ref={measureRef} style={{ position: 'relative' }}>
            <p>The top position of this element is {this.state.position.top}px</p>
            <p>The left position of this element is {this.state.position.left}px</p>
          </div>
        )}
      </Measure>
    );
  }
}

export default MyComponent;

Other packages similar to react-measure

Keywords

FAQs

Package last updated on 26 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc