Function useOffsetHeight

  • Custom React hook that retrieves the offset height of a referenced element.

    This hook listens for resize events on the specified element and updates the offsetHeight state whenever the height of the element changes. The offset height includes padding, scrollbars, and borders, but excludes margins.

    Example

    const MyComponent = () => {
    const ref = useRef<HTMLDivElement>(null);
    const offsetHeight = useOffsetHeight(ref);

    return (
    <div ref={ref}>
    <p>The offset height is: {offsetHeight}px</p>
    </div>
    );
    };

    Parameters

    • ref: THookEventElement<HTMLElement>

      A reference to the element whose offset height is to be measured.

    Returns number