Websites v4 docs v5.2.5
    Preparing search index...

    Function useElementHeight

    • A React hook that tracks the height of a DOM element using ResizeObserver.

      Type Parameters

      • T extends HTMLElement

        The type of HTML element being observed, must extend HTMLElement

      Parameters

      • target: string | RefObject<T | null>

        A React ref object pointing to the element whose height should be tracked, or a class name string

      • options: UseElementHeightOptions = {}

        Optional configuration object

        • defaultHeight

          Initial height to use before the element is measured (defaults to 0)

      Returns number

      The current height of the element in pixels, or the default height if the element is not yet mounted

      const navRef = useRef<HTMLDivElement>(null);
      const navHeight = useElementHeight(navRef, { defaultHeight: 230 });

      // or
      const navHeight = useElementHeight('js-my-class', { defaultHeight: 230 });