Socket
Socket
Sign inDemoInstall

react-with-dimensions

Package Overview
Dependencies
10
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-with-dimensions

React decorator to receive dimensions props generated by ResizeObserver


Version published
Weekly downloads
13K
increased by5.22%
Maintainers
1
Install size
161 kB
Created
Weekly downloads
 

Readme

Source

react-with-dimensions


React decorator to receive dimensions props generated by ResizeObserver.

Installation

npm install --save react-with-dimensions

Usage

Decorated component will receive an addicional dimensions prop with all keys defined in DOMRectReadOnly.

  • x: The x coordinate of the DOMRect's origin
  • y: The y coordinate of the DOMRect's origin
  • width: The width of the DOMRect
  • height: The height of the DOMRect
  • top: Returns the top coordinate value of the DOMRect (usually the same as y)
  • right: Returns the right coordinate value of the DOMRect (usually the same as x + width)
  • bottom: Returns the bottom coordinate value of the DOMRect (usually the same as y + height)
  • left: Returns the left coordinate value of the DOMRect (usually the same as x)
import React, { Component } from 'react'
import withDimensions from 'react-with-dimensions'

//
// decorator
//

@withDimensions
class Box extends Component {
  render() {
    <div>
      <p>width: {this.props.dimensions.width}</p>
      <p>height: {this.props.dimensions.height}</p>
    </div>
  }
}

//
// function
//

class Box extends Component {
  render() {
    <div>
      <p>width: {this.props.dimensions.width}</p>
      <p>height: {this.props.dimensions.height}</p>
    </div>
  }
}

const BoxWithDimensions = withDimensions(Box)

caiogondim.com  ·  GitHub @caiogondim  ·  Twitter @caio_gondim

FAQs

Last updated on 03 Jul 2018

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc