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

react-sizeme

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-sizeme

Make your React Components aware of their width and height.

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
892K
increased by12.93%
Maintainers
1
Weekly downloads
 
Created

What is react-sizeme?

The react-sizeme package is a React higher-order component (HOC) that makes it easy to get the dimensions of a component. It provides a way to measure the size of a component and pass those dimensions as props to the component, enabling responsive design and dynamic rendering based on component size.

What are react-sizeme's main functionalities?

Basic Usage

This example demonstrates the basic usage of react-sizeme. The SizeMe HOC is used to wrap a component, and it injects the size (width and height) as props into the wrapped component.

```jsx
import React from 'react';
import { SizeMe } from 'react-sizeme';

const MyComponent = ({ size }) => (
  <div>
    {`Width: ${size.width}, Height: ${size.height}`}
  </div>
);

const SizeAwareComponent = SizeMe({ monitorHeight: true })(MyComponent);

export default SizeAwareComponent;
```

Using with Functional Components

This example shows how to use react-sizeme with functional components. The SizeMe HOC wraps the functional component and provides the size as props.

```jsx
import React from 'react';
import { SizeMe } from 'react-sizeme';

const MyFunctionalComponent = ({ size }) => (
  <div>
    {`Width: ${size.width}, Height: ${size.height}`}
  </div>
);

const SizeAwareFunctionalComponent = SizeMe({ monitorHeight: true })(MyFunctionalComponent);

export default SizeAwareFunctionalComponent;
```

Custom Configuration

This example demonstrates how to use custom configuration options with react-sizeme. The options include monitoring width and height, setting a refresh rate, and disabling the placeholder.

```jsx
import React from 'react';
import { SizeMe } from 'react-sizeme';

const MyComponent = ({ size }) => (
  <div>
    {`Width: ${size.width}, Height: ${size.height}`}
  </div>
);

const SizeAwareComponent = SizeMe({
  monitorWidth: true,
  monitorHeight: true,
  refreshRate: 100,
  noPlaceholder: true
})(MyComponent);

export default SizeAwareComponent;
```

Other packages similar to react-sizeme

Keywords

FAQs

Package last updated on 19 Apr 2016

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