Skip to content

A React hook that retrieves the window position and dimensions of multiple elements by unique IDs.

License

Notifications You must be signed in to change notification settings

jonahdc/use-multiple-rects

Repository files navigation

useMultipleRects

A React hook that retrieves the window position and dimensions of multiple elements by unique IDs.

Demo: https://use-multiple-rects.now.sh/

Install

npm install --save use-multiple-rects

or

yarn add use-multiple-rects

Usage

import { useMultipleRects } from 'use-multiple-rects';

const example = () => {
  const ids = ['id1', 'id2', 'id3'];

  const [refs, rects] = useMultipleRects({ ids });

  return (
    <>
      <div ref={refs['id1']}>Dimensions: {JSON.stringify(rects['id1'])}</div>
      <div ref={refs['id2']}>Dimensions: {JSON.stringify(rects['id2'])}</div>
      <div ref={refs['id3']}>Dimensions: {JSON.stringify(rects['id3'])}</div>
    </>
  );
};

License

MIT

About

A React hook that retrieves the window position and dimensions of multiple elements by unique IDs.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published