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

1.3.5 • Public • Published

Instalation

npm i react-hook-size --save

Why this hook is the best?

  • Rerenders after mount to get size
  • Uses ResizeObserver(or ponyfill)

Usage

import React, { useRef } from 'react';
import { useSize } from 'react-hook-size';
 
export default function Example() {
    
    let style = {
        width: '100%',
        height: '100%',
    };
    let ref = useRef();
    let { width, height } = useSize(ref);
 
    return (
        <div ref={ref} style={style}>
            <h1>W: {width}, H: {height}</h1>
        </div>
    );
}
 

Package Sidebar

Install

npm i react-hook-size

Weekly Downloads

2,249

Version

1.3.5

License

ISC

Unpacked Size

4.23 kB

Total Files

4

Last publish

Collaborators

  • infodusha