import * as React from "react"; import Measure, { ContentRect, withContentRect, MeasuredComponentProps, MeasurementType } from "react-measure"; class Test extends React.Component { render() { return ( {({measureRef}) => Measure me. } ); } innerRef(ref: Element): void { console.log(`innerRef: ${ref}`); } onResize(contentRect: ContentRect): void { const {client, offset, scroll, bounds, margin} = contentRect; if (client != null) { console.log(`client - top: ${client.top}, left: ${client.left}, width: ${client.width}, height: ${client.height}`); } if (offset != null) { console.log(`offset - top: ${offset.top}, left: ${offset.left}, width: ${offset.width}, height: ${offset.height}`); } if (scroll != null) { console.log(`scroll - top: ${scroll.top}, left: ${scroll.left}, width: ${scroll.width}, height: ${scroll.height}`); } if (bounds != null) { console.log(`bounds - top: ${bounds.top}, left: ${bounds.left}, bottom: ${bounds.bottom}, right: ${bounds.right}, width: ${bounds.width}, height: ${bounds.height}`); } if (margin != null) { console.log(`bounds - top: ${margin.top}, left: ${margin.left}, bottom: ${margin.bottom}, right: ${margin.right}`); } } } class Test2 extends React.Component { render() { return ( {({measureRef}) => } ); } onResize(contentRect: ContentRect): void { } } interface Props { a: string; } const TestFunctionalComponentWithProps: React.SFC = ({a, contentRect, measureRef}) => { return ( {a} ); }; class TestClassComponentWithProps extends React.Component { render() { const {a, contentRect, measureRef} = this.props; return ( {a} ); } } function testHocComponent() { return withContentRect('bounds')(({measureRef, measure, contentRect}) => ( Some content here {JSON.stringify(contentRect, null, 2)} )); } function testHocComponent2() { return withContentRect(['scroll', 'margin'] as ReadonlyArray)(({measureRef}) => ( Some content here )); } const HocComponent = testHocComponent(); const el = ; const MeasuredFunctionalComponent = withContentRect('bounds')(TestFunctionalComponentWithProps); const funcEl = ; const MeasuredClassComponent = withContentRect('bounds')(TestClassComponentWithProps); const classEl = ; function testInnerRefHook() { const ref = React.useRef(); return ; }
{JSON.stringify(contentRect, null, 2)}