Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

@charlietango/use-element-size

Package Overview
Dependencies
Maintainers
2
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@charlietango/use-element-size

Measure the size of a DOM element using ResizeObserver

Source
npmnpm
Version
2.0.2
Version published
Maintainers
2
Created
Source

useElementSize

Measure the size of a DOM element using ResizeObserver

Checkout the Storybook demo.

Installation

yarn add @charlietango/use-element-size
{
  "transformIgnorePatterns": ["<rootDir>/node_modules/(?!@juggle/)"]
}

Alternatively, you could setup it as library that should be mocked.

API

const [ref, size] = useElementSize()

The hook returns an Array with a ref function, and the measured size. Assign the ref to the element you want to measure.

Example

import React from 'react'
import useElementSize from '@charlietango/use-element-size'

const Component = () => {
  const [ref, size] = useElementSize()
  return (
    <div ref={ref}>
      <pre>
        <code>{JSON.stringify(size, null, 2)}</code>
      </pre>
    </div>
  )
}

export default Component

Keywords

react

FAQs

Package last updated on 30 Sep 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