New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@render-props/rect

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@render-props/rect

A state container which provides an interface for retrieving the bounding client rect of a referenced element. The bounding client rect will update each time the window resizes - a behavior which can be turned off by setting the prop `recalcOnWindowResize

  • 0.1.22
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Rect

A state container which provides an interface for retrieving the bounding client rect of a referenced element. The bounding client rect will update each time the window resizes - a behavior which can be turned off by setting the prop recalcOnWindowResize to false. It doesn't provide values for x and y, as IE, Edge and Safari don't have them as part of their DOMRect.

Installation

yarn add @render-props/rect or npm i @render-props/rect


Usage

import Rect from '@render-props/rect'

function DivWithRect (props) {
  return (
    <Rect>
      ({rectRef, recalcRect, top, right, bottom, left, width, height}) => (
        <div ref={rectRef}>
          <div>
            My width: {width}
          </div>
          <div>
            My height: {height}
          </div>
          <div>
            My position: {JSON.stringify({top, right, bottom, left})}
          </div>
        </div>
      )
    </Rect>
  )
}

Props

  • recalcOnWindowResize {bool}: if true, this component will update itself each time a window resize event is detected. Defaults to true.
  • withCoords {bool}: if true, this component will provide its child function with unpacked arguments for its bounding client rect, i.e. {top, right, bottom, left, width, height}. If false, it will provide a function getRect instead which will return the same object just mentioned. Defaults to true.

Render Props

Ref
  • rectRef (element)
    • This ref must be provided to whatever element you are trying to receive the bounding client rect for. e.g. <div ref={rectRef}>
Methods
  • recalcRect
    • remeasures the element bound to rectRef
  • getRect
    • only present if withCoords is set to false. Returns the bounding client rect object.
State

Note: these are only provided if withCoords is true.

  • top {number}: the top coordinate value of the DOMRect
  • right {number}: the right coordinate value of the DOMRect
  • bottom {number}: the bottom coordinate value of the DOMRect
  • left {number}: the left coordinate value of the DOMRect
  • width {number}: the width of the DOMRect
  • height {number}: the height of the DOMRect

Keywords

FAQs

Package last updated on 20 Mar 2019

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