• Custom React hook that retrieves the client width and height of an element.

    This hook listens for resize events on the specified element and updates the clientWidth and clientHeight states whenever the size of the element changes.

    Example

    const MyComponent = () => {
    const ref = useRef(null);
    const { clientWidth, clientHeight } = useClientSize(ref);

    return (
    <div ref={ref}>
    <p>Width: {clientWidth}px</p>
    <p>Height: {clientHeight}px</p>
    </div>
    );
    };

    Parameters

    • ref: THookEventElement<Element>

      A reference to the element whose client size is to be measured.

    Returns {
        clientHeight: number;
        clientWidth: number;
    }

    • clientHeight: number
    • clientWidth: number