question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot execute updateRect on ref.current.

See original GitHub issue

Environments

  • Framework name: react-moveable / React
  • Framework version: 0.39.3
  • Moveable Component version:
  • Testable Address(optional):

Description

I am updating my component’s data, and also changing transform/translate values, everything works ok, except the control box, which moves more than needed, I have deduced it is due to the miscalculations, and I need to use updateRect to fix it.

I try to update it after I update my state in onDragEnd event, using moveableRef.current.updateRect(), I do not get any error, however, it does not seem to change anything. Below is a screenshot, green box is where controlbox supposed to be. Animation

I inspected moveableRef.current and there is no such function in there, see screenshot below. image

If I call moveableRef.updateRect() - it seems to work, and the controlbox updates. See screenshot below.

Animation2

However, I then get error, that no such function exists. image

Why it works, when I get the error, and it does not work, when it is supposed to work ? Am I missing some setup ?

My Moveable :

image

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
daybrushcommented, Nov 6, 2022

@SarunasMedeikis It will be because of the transform you set.

Since the state of React is asynchronous, the rect of the moveable is calculated without all styles applied.

e.target.style.cssText +=
            `left: ${target.left}px;` +
            `top: ${target.top}px;` +
            `transform: translate(0px, 0px)`;
          frame.translate = [0, 0, 0, 0];

And check the box-sizing: border-box property of the target?

rect is offsetWidth and offsetHeight. The width and height are gradually increased.

.target {
   box-sizing: border-box;
}
0reactions
SarunasMedeikiscommented, Nov 6, 2022

Thank you for the help 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

(React Hooks) Ref method not updating state value
First lets start with small tweaks: useImperativeHandle should be used with dep array, in this case its empty: useImperativeHandle(...,[]);.
Read more >
useEffect(effect, [ref.current]) is prematurely re-running #14387
It seems useEffect(effect, [ref.current]) is re-running under certain circumstances without the current ref identity changing.
Read more >
Refs and the DOM - React
When the ref attribute is used on an HTML element, the ref created in the constructor with React.createRef() receives the underlying DOM element...
Read more >
The Complete Guide to useRef() and Refs in React
How to use React.useRef() hook to create persisted mutable values (also known as references or refs), as well access DOM elements.
Read more >
Accessing previous props or state with React Hooks
While there's currently no React Hook that does this out of the box, ... code will run when the value of 'value' changes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found