Track The Size Of DOM In React – use-element-size

Category: Others , React
Author:alloc
Views Total:6 views
Official Page:Go to website
Publish Date:August 20, 2020
License:MIT

use-element-size is a React hook for tracking the size of React-dom element in the React app.

Install & Import:

# NPM
$ npm i use-element-size --save
import React from 'react'
import { useElementSize } from 'use-element-size'

Basic usage:

onst Example = () => {
  const ref = useElementSize((size, prevSize, elem) => {
    console.log({ size, prevSize, elem })
  })
  return (
    <div
      ref={ref}
      style={{
        position: 'relative',
        width: '50%',
        height: '50%',
      }}
    />
  )
}

Preview:

Track The Size Of DOM In React - use-element-size

You Might Be Interested In:

Leave a Reply