New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-element-onresize

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-element-onresize

Detect element resizing from your components

latest
npmnpm
Version
1.0.6
Version published
Maintainers
1
Created
Source

React element resize observer

A simple React Higher-Order Component who handle element resize detection from your React Components.

Installation

npm install react-element-onresize --save-dev

Browser Support

With ResizeObserver Polyfill

Build Status

NOTE: Internet Explorer 8 and its earlier versions are not supported.

Without any Polyfill

Without any Polyfill

Usage

ESNext syntax with decorators

import React, { Component } from 'react';
import ElementResize from 'react-element-onresize';

@ElementResize()
class App extends Component {
  constructor(props){
    super(props);
  }

  render(){
    const { elemResize } = this.props;

    return (
      <div>
        <p>width: {(elemResize.contentRect)? Math.floor(elemResize.contentRect.width) : 0} px</p>
        <p>height: {(elemResize.contentRect)? Math.floor(elemResize.contentRect.height) : 0} px</p>
      </div>
    )
  }
}

export default App;

ES6 syntax

import React, { Component } from 'react';
import ElementResize from 'react-element-onresize';

class App extends Component {
  constructor(props){
    super(props);
  }

  render(){
    const { elemResize } = this.props;

    return (
      <div>
        <p>width: {(elemResize.contentRect)? Math.floor(elemResize.contentRect.width) : 0} px</p>
        <p>height: {(elemResize.contentRect)? Math.floor(elemResize.contentRect.height) : 0} px</p>
      </div>
    )
  }
}

export default ElementResize()(App);

Polyfill usage

import React, { Component } from 'react';
import ElementResize from 'react-element-onresize';
import resizeObserver from "resize-observer-polyfill";

@ElementResize(resizeObserver)
class App extends Component {
  constructor(props){
    super(props);
  }

  render(){
    const { elemResize } = this.props;

    return (
      <div>
        <p>width: {(elemResize.contentRect)? Math.floor(elemResize.contentRect.width) : 0} px</p>
        <p>height: {(elemResize.contentRect)? Math.floor(elemResize.contentRect.height) : 0} px</p>
      </div>
    )
  }
}

export default App;

Keywords

react-element-onresize

FAQs

Package last updated on 12 Dec 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