0.2.1 • Published 8 years ago
@davidisaaclee/react-measure-bounds v0.2.1
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
requestAnimationFrameto minimize layout thrashing - Adds a wrapper DOM component to the hierarchy
Install
yarn add @davidisaaclee/react-measure-boundsDevelopment
# 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 testSee also
- fastdom: Batch DOM measurements / mutations to
requestAnimationFramecalls. This library uses a sub-componentBatchForAnimationFrame, which behaves similarly to fastdom. - ResizeObserver
- CSS-Element-Queries