JSPM

  • Created
  • Published
  • Downloads 258508
  • Score
    100M100P100Q172171F
  • License MIT

Measure React elements position in the DOM

Package Exports

  • @reach/rect
  • @reach/rect/dist/reach-rect.cjs.js
  • @reach/rect/dist/reach-rect.mjs

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@reach/rect) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@reach/rect

Stable release MIT license

Docs | Source

Measures DOM elements (aka. bounding client rect). See also Element.getBoundingClientRect()

import { Rect, useRect } from "@reach/rect";

function Example() {
    const ref = React.useRef();
    const rect = useRect(ref);

    return (
        <div>
            <pre>{JSON.stringify(rect, null, 2)}</pre>
            <div
                ref={ref}
                contentEditable
                dangerouslySetInnerHTML={{
                    __html: "Edit this to change the size!",
                }}
            />
        </div>
    );
}