Skip to content

useSize

Track the element size easily using useResizeObserver.

Options

Return Values

NameTypeDescription
refRefObjectthe target element reference.
widthNumberthe target's width.
heightNumberthe target's height.

Example Usage

tsx
import { useSize } from 'react-pre-hooks';

export default function Example() {
  const { ref, width, height } = useSize<HTMLTextAreaElement>();

  return (
    <main>
      <textarea ref={ref} disabled>
        Resize me!
      </textarea>
    </main>
  );
}
import { useSize } from 'react-pre-hooks';

export default function Example() {
  const { ref, width, height } = useSize<HTMLTextAreaElement>();

  return (
    <main>
      <textarea ref={ref} disabled>
        Resize me!
      </textarea>
    </main>
  );
}

Released under the MIT License.