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.

Immediately after `setState` target, the `moveable.target` is still not updated directly

See original GitHub issue

Environments

Description

I need to handle the scenario when the user mousedown the targeted element, it can immediately be dragged.

To do it, I need to run this kind of code on mousedown the element:

target.addEventListener("mousedown", (e) => {
  moveable.setState({
    target: [target]
  });
  moveable.dragStart(e);
});

It was working before, until recently I realized after upgrade to the latest package, it doesn’t work anymore. The reason seems like because right after moveable.setState({ target: targetElem }), it doesn’t immediately set the moveable.target.

I created the codesandbox to replicate the issue. This is the screenshot:

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
daybrushcommented, Mar 13, 2022

@chenxeed

  • moveable 0.28.0
  • react-moveable 0.31.1
  • preact-moveable 0.30.0
  • ngx-moveable 0.24.0
  • svelte-moveable 0.18.0
  • lit-moveable 0.5.0
  • vue-moveable 2.0.0-beta.6
  • vue3-moveable 0.3.0

moveable’s new version is released. and forceUpdate method is added. Check it again.

1reaction
daybrushcommented, Nov 22, 2021

@chenxeed

setState is asynchronous and forceUpdate is a synchronous method.

I will add a forceUpdate method to the moveable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React setState not Updating Immediately - Stack Overflow
First set your value. after proceed your works. this.setState({inputvalue: e.target.value}, function () { this.
Read more >
Why React doesn't update state immediately - LogRocket Blog
When developing React applications, you may have noticed that state updates don't immediately reflect new values after being changed.
Read more >
What Every React Developer Should Know About State
1. State updates with useState are not merged. One challenge many React developers face when moving from class-based components to function ...
Read more >
Lifting State Up - React
Inside these methods, the Calculator component asks React to re-render itself by calling this.setState() with the new input value and the current scale...
Read more >
Change target and start dragging in one event #82 - GitHub
Hello, I'm trying to use a single moveable object for multiple elements. Based on #55, I've implemented the changing of the target property ......
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