werkbank
    Preparing search index...

    Function useResizeObserver

    • Watches for size changes of an element using ResizeObserver.

      Type Parameters

      • T extends Element

        The element type.

      Parameters

      • cb: (e: Entries) => VoidFn | undefined

        The callback to execute on resize.

      Returns RefObject<T | null>

      A ref object to attach to the target element.

      This hook returns a ref to attach to the element. The callback receives the ResizeObserverEntry array. The callback can optionally return a cleanup function.

      const ref = useResizeObserver((entries) => {
      for (const entry of entries) {
      console.log(entry.contentRect);
      }
      });
      return <div ref={ref} />;