@react-hook/size
Advanced tools
Comparing version 1.0.0 to 2.0.0
@@ -75,23 +75,20 @@ 'use strict' | ||
const targetEl = target && 'current' in target ? target.current : target | ||
const initialRect = targetEl | ||
? targetEl.getBoundingClientRect() | ||
: { | ||
width: | ||
(_options$initialWidth = | ||
options === null || options === void 0 | ||
? void 0 | ||
: options.initialWidth) !== null && | ||
_options$initialWidth !== void 0 | ||
? _options$initialWidth | ||
: 0, | ||
height: | ||
(_options$initialHeigh = | ||
options === null || options === void 0 | ||
? void 0 | ||
: options.initialHeight) !== null && | ||
_options$initialHeigh !== void 0 | ||
? _options$initialHeigh | ||
: 0, | ||
} | ||
return [initialRect.width, initialRect.height] | ||
return targetEl | ||
? [targetEl.offsetWidth, targetEl.offsetHeight] | ||
: [ | ||
(_options$initialWidth = | ||
options === null || options === void 0 | ||
? void 0 | ||
: options.initialWidth) !== null && | ||
_options$initialWidth !== void 0 | ||
? _options$initialWidth | ||
: 0, | ||
(_options$initialHeigh = | ||
options === null || options === void 0 | ||
? void 0 | ||
: options.initialHeight) !== null && | ||
_options$initialHeigh !== void 0 | ||
? _options$initialHeigh | ||
: 0, | ||
] | ||
}) | ||
@@ -101,9 +98,8 @@ ;(0, _passiveLayoutEffect.default)(() => { | ||
if (!targetEl) return | ||
const rect = targetEl.getBoundingClientRect() | ||
setSize([rect.width, rect.height]) | ||
setSize([targetEl.offsetWidth, targetEl.offsetHeight]) | ||
}, [target]) // Where the magic happens | ||
;(0, _resizeObserver.default)(target, (entry) => { | ||
const {width, height} = entry.contentRect | ||
setSize([width, height]) | ||
const target = entry.target | ||
setSize([target.offsetWidth, target.offsetHeight]) | ||
}) | ||
@@ -110,0 +106,0 @@ return size |
@@ -16,23 +16,20 @@ import * as React from 'react' | ||
const targetEl = target && 'current' in target ? target.current : target | ||
const initialRect = targetEl | ||
? targetEl.getBoundingClientRect() | ||
: { | ||
width: | ||
(_options$initialWidth = | ||
options === null || options === void 0 | ||
? void 0 | ||
: options.initialWidth) !== null && | ||
_options$initialWidth !== void 0 | ||
? _options$initialWidth | ||
: 0, | ||
height: | ||
(_options$initialHeigh = | ||
options === null || options === void 0 | ||
? void 0 | ||
: options.initialHeight) !== null && | ||
_options$initialHeigh !== void 0 | ||
? _options$initialHeigh | ||
: 0, | ||
} | ||
return [initialRect.width, initialRect.height] | ||
return targetEl | ||
? [targetEl.offsetWidth, targetEl.offsetHeight] | ||
: [ | ||
(_options$initialWidth = | ||
options === null || options === void 0 | ||
? void 0 | ||
: options.initialWidth) !== null && | ||
_options$initialWidth !== void 0 | ||
? _options$initialWidth | ||
: 0, | ||
(_options$initialHeigh = | ||
options === null || options === void 0 | ||
? void 0 | ||
: options.initialHeight) !== null && | ||
_options$initialHeigh !== void 0 | ||
? _options$initialHeigh | ||
: 0, | ||
] | ||
}) | ||
@@ -42,9 +39,8 @@ useLayoutEffect(() => { | ||
if (!targetEl) return | ||
const rect = targetEl.getBoundingClientRect() | ||
setSize([rect.width, rect.height]) | ||
setSize([targetEl.offsetWidth, targetEl.offsetHeight]) | ||
}, [target]) // Where the magic happens | ||
useResizeObserver(target, (entry) => { | ||
const {width, height} = entry.contentRect | ||
setSize([width, height]) | ||
const target = entry.target | ||
setSize([target.offsetWidth, target.offsetHeight]) | ||
}) | ||
@@ -51,0 +47,0 @@ return size |
{ | ||
"name": "@react-hook/size", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"homepage": "https://github.com/jaredLunde/react-hook#readme", | ||
@@ -5,0 +5,0 @@ "repository": "github:jaredLunde/react-hook", |
@@ -38,2 +38,3 @@ <hr> | ||
- [x] Determines the size of the element including any padding, borders, and scroll bars. | ||
- [x] The size reported by the hook updates each time the size of the element changes. | ||
@@ -40,0 +41,0 @@ - [x] Uses a single `ResizeObserver` for tracking all elements used by the hooks. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
93
16602
232