react-dimensions-hook
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

react-dimensions-hook

This package allows you to measure the size of any HTML element inside one of your React functional components using hooks.

Usage

import { useDimensions } from 'react-dimensions-hook';
 
function MyComponent() {
  const { ref, dimensions } = useDimensions();
 
  return (
    <div
      ref={ref}
      style={{
        width: '500px',
        height: '100px',
        margin: '0 auto'
      }}
    >
      my size is {dimensions.width} × {dimensions.height}
    </div>
  );
}

Features

Attribution

While this package was written from scratch, inspiration was gained from react-dimensions, react-sizeme, and react-use-dimensions

/react-dimensions-hook/

    Package Sidebar

    Install

    npm i react-dimensions-hook

    Weekly Downloads

    243

    Version

    1.0.3

    License

    ISC

    Unpacked Size

    7.52 kB

    Total Files

    8

    Last publish

    Collaborators

    • borremosch