@notthatnathan/use-element-size

    1.1.5 • Public • Published

    useElementSize

    Pass an element ref that you’d like to observe. Its initial and changing width and height are returned.

    Example:

    const ParentComponent = () => {
      const parentRef = useRef(null)
      const [width, height] = useElementSize(parentRef)
    
      return (
        <div ref={parentRef}>
          <MyComponent parentWidth={width} parentHeight={height} />
        </div>
      )
    }

    Read the blog post

    TODO

    Use a single ResizeObserver (Read more) Limit updates with requestAnimationFrame

    Keywords

    none

    Install

    npm i @notthatnathan/use-element-size

    DownloadsWeekly Downloads

    55

    Version

    1.1.5

    License

    MIT

    Unpacked Size

    27.4 kB

    Total Files

    16

    Last publish

    Collaborators

    • notthatnathan