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

How to convert React-Draggable coordinates into Element.getBoundingClientRect()?

Open tetron432 opened this issue 3 years ago • 1 comments

I noticed that the x and y coordinates that React-Draggable gives out is completely different from what getBoundingClientRect gives out. Here's a snippet of my code:

const [position, setPosition] = useState({ x: 0, y: 0 });
const trackPos = (data) => {
     setPosition({ x: data.x, y: data.y });
};

<Draggable onDrag={(e, data) => trackPos(data)}>
     <div ref = {ref}>...</div>
</Draggable>

When I print out the values of both ref.getBoundingClientRect() from the component and that of data are completely different. Is there any way to convert these values?

tetron432 avatar Dec 31 '22 18:12 tetron432

i'd like to understand what do x and y in data stand for. does it depend on handle prop we pass to Draggable? does it depend on position prop?

okramovic avatar Feb 14 '23 09:02 okramovic