Skip to content

Latest commit

Β 

History

History
37 lines (27 loc) Β· 649 Bytes

useSize.md

File metadata and controls

37 lines (27 loc) Β· 649 Bytes

useSize

React sensor hook that tracks size of an HTML element.

Usage

import {useSize} from 'react-use';

const Demo = () => {
  const [sized, {width, height}] = useSize(
    ({width}) => <div style={{background: 'red'}}>Size me up! ({width}px)</div>,
    { width: 100, height: 100 }
  );

  return (
    <div>
      {sized}
      <div>width: {width}</div>
      <div>height: {height}</div>
    </div>
  );
};

Reference

useSize(element, initialSize);
  • element β€” sized element.
  • initialSize β€” initial size containing a width and height key.

Related hooks