Immediately after `setState` target, the `moveable.target` is still not updated directly
See original GitHub issueEnvironments
- Framework name: moveable
- Framework version:
v0.25.4-beta0
tov0.27.2
- Moveable Component version: -
- Testable Address(optional): https://codesandbox.io/s/silly-dream-ihd5s?file=/src/index.ts
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:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@chenxeed
moveable
0.28.0react-moveable
0.31.1preact-moveable
0.30.0ngx-moveable
0.24.0svelte-moveable
0.18.0lit-moveable
0.5.0vue-moveable
2.0.0-beta.6vue3-moveable
0.3.0moveable’s new version is released. and
forceUpdate
method is added. Check it again.@chenxeed
setState is asynchronous and forceUpdate is a synchronous method.
I will add a forceUpdate method to the moveable.