react-use icon indicating copy to clipboard operation
react-use copied to clipboard

useMeasure hook shows wrong X value?

Open Floriferous opened this issue 4 years ago • 10 comments

What is the current behavior?

I'm not sure if I understand the useMeasure correctly, but the goal is for it to return the boundingClientRect of the element right?

If that is the case, then the x value, and probably others, seem to be wrong, as it's always 0 on my end.

Steps to reproduce it and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn't have extra dependencies other than react-use. Paste the link to your JSFiddle or CodeSandbox example below: Here's a very simple reproduction: https://codesandbox.io/s/broken-browser-lh313?file=/src/App.js

I compared it with the DOM API on the same node so you can see what I expect.

What is the expected behavior? I expect the result of useMeasure left and X to match the ones from the DOM.

A little about versions:

  • React: latest
  • react-use: latest
  • Did this worked in the previous package version? don't know

Floriferous avatar Dec 18 '20 13:12 Floriferous

I have the same issue too.

birkanozer avatar Jan 24 '21 15:01 birkanozer

i thought this worked properly, but it seems broken in the current version

macrozone avatar Feb 22 '21 15:02 macrozone

For me width & height are inverted.

Did you guys find the last stable version for useMeasure?

fcisio avatar Mar 23 '21 17:03 fcisio

I have the same problem, top and left are always 0

Forked the codesandbox above and copy useMeasure to inspect the error: https://codesandbox.io/s/little-dream-fbtp6?file=/src/useMeasure.js:609-655 the contectRect has difetent info than target.getBoundingClientRect in the observed target

tomasdisk avatar Jun 03 '21 16:06 tomasdisk

Hey @tomasdisk You can take a look at react-hookz, a bunch of guys from here has created it since react-use seems to be dead at this point.

They have a useMesure hook.

fcisio avatar Jun 03 '21 17:06 fcisio

@fcisio Thanks for the info! I'll check it 😄

tomasdisk avatar Jun 03 '21 19:06 tomasdisk

Upping this thread so it won't become stale.

Facing same issue, any chance the PR would be merged?

yournatalita avatar Dec 02 '21 08:12 yournatalita

I have the same issue too. top and left are always 0

MarwenLabidi avatar Oct 02 '22 19:10 MarwenLabidi

same issue here in 2023

gocreating avatar Aug 12 '23 15:08 gocreating