Skip to content

Commit

Permalink
Removed findDOMNode call and use refs
Browse files Browse the repository at this point in the history
  • Loading branch information
fcsonline committed Mar 28, 2017
1 parent d2df877 commit 9eec4dc
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/Measure.jsx
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -42,8 +41,6 @@ class Measure extends Component {
}

componentDidMount() {
this._setDOMNode()

// measure on first render
this.measure()

Expand All @@ -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,
Expand All @@ -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')

Expand Down Expand Up @@ -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 (
<div ref={(c) => { this._node = c; }}>
{ filtered }
</div>
)
}
}
Expand Down

0 comments on commit 9eec4dc

Please sign in to comment.