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

@rb/resize-observer

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rb/resize-observer

ResizeObserver component for React

  • 0.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-50%
Maintainers
2
Weekly downloads
 
Created
Source

resize-observer

ResizeObserver component for React.

Purpose

Get notifications when an in the page changes its size.

The change in size can have any source - layout changes, DOM changes, browser resize - etc. The source is not important.

The ResizeObserver API is a performant way of getting updates on size changes.

Warning! Only works if the global ResizeObserver is available. (As of January 2018 only Chrome >= 64 ships it natively.) You could use a polyfill to ensure it's available.

Install

$ npm install @rb/resize-observer --save

# or

$ yarn add @rb/resize-observer

Usage

This component can be nested inside any parent component, and will notify when the node of the parent component changes its size.

import React from 'react';
import { render } from 'react-dom';

import ResizeObserver from '@rb/resize-observer';

const App = () => {
  return (
    <div style={{ width: '50vw', border: '1px solid red' }}>
      This element has width: 50vw, so resize the browser window to get
      notifications in the console
      <ResizeObserver
        onResize={({ width, height }) => {
          console.log({ width, height });
        }}
      />
    </div>
  );
};

render(<App />, document.getElementById('root'));

Props

  • onResize: (contentRect) - you can specify an onResize function prop, which will be called with the contentRect passed by the native ResizeObserver API. You can destructure this to {width, height}

License

MIT

Keywords

FAQs

Package last updated on 27 Apr 2018

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