From 9eec4dc3d9664ad9e91e6291d2e250f9a9c9e565 Mon Sep 17 00:00:00 2001 From: Ferran Basora Date: Tue, 28 Mar 2017 10:09:41 +0000 Subject: [PATCH] Removed findDOMNode call and use refs --- src/Measure.jsx | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/Measure.jsx b/src/Measure.jsx index 6854cf9..dbdd64d 100644 --- a/src/Measure.jsx +++ b/src/Measure.jsx @@ -1,5 +1,4 @@ import React, { Component, Children, PropTypes, createElement, cloneElement } from 'react' -import ReactDOM from 'react-dom' import ResizeObserver from 'resize-observer-polyfill' import getNodeDimensions from 'get-node-dimensions' @@ -42,8 +41,6 @@ class Measure extends Component { } componentDidMount() { - this._setDOMNode() - // measure on first render this.measure() @@ -66,10 +63,6 @@ class Measure extends Component { this._node = null } - _setDOMNode() { - this._node = ReactDOM.findDOMNode(this) - } - getDimensions( node = this._node, includeMargin = this.props.includeMargin, @@ -90,11 +83,6 @@ class Measure extends Component { // bail out if we shouldn't measure if (!this.props.shouldMeasure) return - // if no parent available we need to requery the DOM node - if (!this._node.parentNode) { - this._setDOMNode() - } - const dimensions = this.getDimensions(this._node, includeMargin, useClone) const isChildFunction = (typeof this.props.children === 'function') @@ -124,10 +112,15 @@ class Measure extends Component { render() { const { children } = this.props - return Children.only( + const filtered = Children.only( typeof children === 'function' ? children(this.state.dimensions) : children + ); + return ( +
{ this._node = c; }}> + { filtered } +
) } }