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

latest
Source
npmnpm
Version
2.2.0
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

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 14 Apr 2022

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