@phenomenon-hooks/use-get-bounding-client-rect
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

useGetBoundingClientRect


Installation

yarn add @phenomenon-hooks/use-get-bounding-client-rect

or

npm i @phenomenon-hooks/use-get-bounding-client-rect

Usage

import React from 'react';
import { useGetBoundingClientRect } from '@phenomenon-hooks/use-get-bounding-client-rect';

const Component: React.FC = () => {
    const ref = React.useRef(null);
    const [clientRect] = useGetBoundingClientRect(ref);

    const { top, right, bottom, left, width, height } = clientRect;

    return (
        <div>
            <div ref={ref}>Some content</div>
            <p>Top: {top}</p>
            <p>Right: {right}</p>
            <p>Bottom: {bottom}</p>
            <p>Left: {left}</p>
            <p>Width: {width}</p>
            <p>Height: {height}</p>
        </div>
    );
};

Anatomy

const [clientRect, startToSetClientRect] = useGetBoundingClientRect(ref);

Arguments

Argument Type Description
ref Ref<HTMLElement> React ref object of element. (Generic)

Returns

Return value Type Description
clientRect DOMRect ClientRect object of element. (Generic)
startToSetClientRect Function Function to start to set ClientRect object of element

Readme

Keywords

none

Package Sidebar

Install

npm i @phenomenon-hooks/use-get-bounding-client-rect

Weekly Downloads

3

Version

0.0.2

License

MIT

Unpacked Size

9.65 kB

Total Files

8

Last publish

Collaborators

  • mykola.kolomoyets