react-measure
Advanced tools
Comparing version 2.2.6 to 2.3.0
## CHANGELOG | ||
### 2.3.0 | ||
Fix regression with `contentRect.bounds` not getting called properly | ||
Note that `onResize` will get called twice when first mounting now | ||
### 2.2.6 | ||
@@ -4,0 +10,0 @@ |
@@ -110,3 +110,2 @@ 'use strict'; | ||
_this._node = null; | ||
_this._firstResize = true; | ||
@@ -121,3 +120,3 @@ _this.measure = function (entries) { | ||
_this._animationFrameID = window.requestAnimationFrame(function () { | ||
if (_this._resizeObserver !== null && !_this._firstResize) { | ||
if (_this._resizeObserver !== null) { | ||
_this.setState({ | ||
@@ -131,4 +130,2 @@ contentRect: contentRect | ||
} | ||
_this._firstResize = false; | ||
}); | ||
@@ -135,0 +132,0 @@ }; |
@@ -104,3 +104,2 @@ import _extends from '@babel/runtime/helpers/esm/extends'; | ||
_this._node = null; | ||
_this._firstResize = true; | ||
@@ -115,3 +114,3 @@ _this.measure = function (entries) { | ||
_this._animationFrameID = window.requestAnimationFrame(function () { | ||
if (_this._resizeObserver !== null && !_this._firstResize) { | ||
if (_this._resizeObserver !== null) { | ||
_this.setState({ | ||
@@ -125,4 +124,2 @@ contentRect: contentRect | ||
} | ||
_this._firstResize = false; | ||
}); | ||
@@ -129,0 +126,0 @@ }; |
@@ -1071,3 +1071,2 @@ (function (global, factory) { | ||
_this._node = null; | ||
_this._firstResize = true; | ||
@@ -1082,3 +1081,3 @@ _this.measure = function (entries) { | ||
_this._animationFrameID = window.requestAnimationFrame(function () { | ||
if (_this._resizeObserver !== null && !_this._firstResize) { | ||
if (_this._resizeObserver !== null) { | ||
_this.setState({ | ||
@@ -1092,4 +1091,2 @@ contentRect: contentRect | ||
} | ||
_this._firstResize = false; | ||
}); | ||
@@ -1096,0 +1093,0 @@ }; |
{ | ||
"name": "react-measure", | ||
"version": "2.2.6", | ||
"version": "2.3.0", | ||
"description": "Compute measurements of React components.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.cjs.js", |
@@ -81,4 +81,3 @@ ## 📏 React Measure | ||
Callback invoked when either element width or height have changed. Note that | ||
this will be called on mount to get the initial values. | ||
Callback invoked when either element width or height have changed. Note that this will be called twice on mount to get the initial values. The first call will come from `componentDidMount` while the second call will come from the `ResizeObserver`. | ||
@@ -85,0 +84,0 @@ #### `children`: PropTypes.func |
@@ -45,3 +45,3 @@ import React, { createRef } from 'react' | ||
expect(defaultChildrenFn).toHaveBeenCalledTimes(1) | ||
expect(defaultChildrenFn).toHaveBeenCalledTimes(2) | ||
expect(container.firstChild).toMatchSnapshot() | ||
@@ -57,3 +57,3 @@ }) | ||
expect(defaultChildrenFn).toHaveBeenCalledTimes(1) | ||
expect(defaultChildrenFn).toHaveBeenCalledTimes(2) | ||
expect(container.firstChild).toMatchSnapshot() | ||
@@ -106,5 +106,5 @@ }) | ||
expect(onResize).toHaveBeenCalledTimes(1) | ||
expect(onResize).toHaveBeenCalledTimes(2) | ||
}) | ||
}) | ||
}) |
@@ -38,4 +38,2 @@ import { Component, createElement } from 'react' | ||
_firstResize = true | ||
componentDidMount() { | ||
@@ -73,3 +71,3 @@ this._resizeObserver = new ResizeObserver(this.measure) | ||
this._animationFrameID = window.requestAnimationFrame(() => { | ||
if (this._resizeObserver !== null && !this._firstResize) { | ||
if (this._resizeObserver !== null) { | ||
this.setState({ contentRect }) | ||
@@ -80,3 +78,2 @@ if (typeof this.props.onResize === 'function') { | ||
} | ||
this._firstResize = false | ||
}) | ||
@@ -83,0 +80,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
80397
1742
194