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

react-resize-detector

Package Overview
Dependencies
Maintainers
2
Versions
120
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-resize-detector

React resize detector

  • 12.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.3M
decreased by-0.64%
Maintainers
2
Weekly downloads
 
Created

What is react-resize-detector?

The react-resize-detector is a React component designed to handle resize events for React elements. It provides a simple and efficient way to trigger a function or render logic when the size of an element changes. This is particularly useful in responsive designs and when elements need to adjust based on their container's dimensions.

What are react-resize-detector's main functionalities?

Basic resize detection

This feature allows you to detect the size of a component and react to changes. The `useResizeDetector` hook provides `width`, `height`, and `ref` which you attach to the component you want to monitor. The component re-renders whenever the size changes, displaying the new dimensions.

import React from 'react';
import useResizeDetector from 'react-resize-detector';

const ResponsiveComponent = () => {
  const { width, height, ref } = useResizeDetector();
  return (
    <div ref={ref}>
      Size: {width} x {height}
    </div>
  );
};

export default ResponsiveComponent;

OnResize callback

This feature uses the `withResizeDetector` higher-order component to monitor size changes. It provides `width`, `height`, and an `onResize` callback that is triggered on every resize event. This is useful for performing actions or calculations based on the new size.

import React from 'react';
import { withResizeDetector } from 'react-resize-detector';

class MyComponent extends React.Component {
  render() {
    const { width, height, onResize } = this.props;
    return (
      <div onResize={onResize}>
        Current size: {width} x {height}
      </div>
    );
  }
}

export default withResizeDetector(MyComponent, {
  handleWidth: true,
  handleHeight: true,
  onResize: (width, height) => console.log(`Resized to ${width} x ${height}`)
});

Other packages similar to react-resize-detector

Keywords

FAQs

Package last updated on 13 Dec 2024

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