@davidisaaclee/react-measure-bounds

0.2.1 • Public • Published

react-measure-bounds

A React component which provides a way to measure its own bounding client rect.

<MeasureBounds>
  {(getBoundingClientRect) => (
    <button
      onClick={_ =>
        // getBoundingClientRect :: () -> Promise<DOMRect>
        getBoundingClientRect()
          .then(bounds => console.log(`Bounds: ${bounds}`))}
    />
  )}
</MeasureBounds>
  • Batches measurements to requestAnimationFrame to minimize layout thrashing
  • Adds a wrapper DOM component to the hierarchy

Install

yarn add @davidisaaclee/react-measure-bounds

Development

# Clone repository.
git clone https://github.com/davidisaaclee/react-measure-bounds
cd react-measure-bounds

# Build for ES modules and CommonJS.
yarn build

# Run tests.
yarn test

See also

  • fastdom: Batch DOM measurements / mutations to requestAnimationFrame calls. This library uses a sub-component BatchForAnimationFrame, which behaves similarly to fastdom.
  • ResizeObserver
  • CSS-Element-Queries

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.2.1
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.2.1
    0
  • 0.2.0
    0
  • 0.1.0
    0

Package Sidebar

Install

npm i @davidisaaclee/react-measure-bounds

Weekly Downloads

0

Version

0.2.1

License

MIT

Unpacked Size

98.2 kB

Total Files

8

Last publish

Collaborators

  • davidisaaclee