Skip to content

hoologic/use-element

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@hoologic/use-element

React hook providing a typed element DOM reference via a ref callback.

Usage

import { useElement } from '@hoologic/use-element'
import { useEffect } from 'react'

const Component = () => {
  const [element, refCallback] = useElement<HTMLDivElement>()

  useEffect(() => {
    if (!element) return

    const { height, width } = element.getBoundingClientRect()

    console.log(height, width)
  }, [element])

  return <div ref={refCallback}>Content</div>
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published