Closed chenxeed closed 2 years ago
From my investigation, it might have something to do with react-simple-compat
changes here:
It makes the state changes become asynchronous, thus the target is not immediately updated.
@chenxeed
Try it like the code below:
moveable.setState({
target: [target]
}, () => {
moveable.dragStart(e);
});
I can do that, however in my code logic, the code that set the moveable
target state and the one to immediate dragstart is different, thus I can't really set a callback for that.
I saw that in the setState
from react-simple-compat
, it has 3rd parameter isForceUpdate
to update the state synchronously.
https://github.com/daybrush/react-simple-compat/blob/master/src/Compat.tsx#L520
However the 3rd param is not accessible through the moveable.setState
. I wonder if it's intended, or we can improve the moveable.setState
to also accept the 3rd param for isForceUpdate
.
@chenxeed
setState is asynchronous and forceUpdate is a synchronous method.
I will add a forceUpdate method to the moveable.
@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.
Environments
v0.25.4-beta0
tov0.27.2
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:
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 themoveable.target
.I created the codesandbox to replicate the issue. This is the screenshot: