useDimensions
useDimensions copied to clipboard
Fix top & left calculation
Fixes #12
Would this not be better as
top: "top" in rect ? rect.top : rect.y,
left: "left" in rect ? rect.left : rect.x,
In older browsers, the getBoundingClientRect
function doesn't return with the x
and y
.
Every browser fills the top
and left
properties so the first part of your condition is always true.
So if top and left always exist, why polyfill them?
in fact, maybe the function should check if any props are missing, and otherwise return the object unchanged.
I fixed. Thank you @wmertens 👍
I found this as well.
Actually both top
and left
are inverted.
const [ref, { x: left, y: top}] = useDimensions()
@Swizec can you check this PR, please?