moveable icon indicating copy to clipboard operation
moveable copied to clipboard

React Moveable ref set target with setState not working

Open ngocducdim opened this issue 3 years ago • 5 comments

Hi, in React I have the moveable ref, when mousedown to the component I use setState to set the target but it not affect: image The codesanbox: https://codesandbox.io/embed/vibrant-mestorf-j5byc1?fontsize=14&hidenavigation=1&theme=dark

ngocducdim avatar Aug 05 '22 05:08 ngocducdim

@ngocducdim

sorry but you can't use moveable.setState

You must use the target={target} prop.

daybrush avatar Aug 05 '22 13:08 daybrush

@ngocducdim

I'll add waitToChangeTarget method for dragStart.

moveable.waitToChangeTarget().then(() => {
    moveable.dragStart(e);
});
setTarget(target);

daybrush avatar Aug 05 '22 17:08 daybrush

@ngocducdim

moveable's new version is released.

waitToChangeTarget method is added.

moveable.waitToChangeTarget().then(() => {
    moveable.dragStart(e);
});
setTarget(target);

daybrush avatar Aug 06 '22 03:08 daybrush

Update the sandbox it work, but when integrate with my project

moveable.waitToChangeTarget().then(() => {
    console.log('updated');
});

the console never log the 'updated', maybe because I use Selecto package, thanks you anyway for the work

ngocducdim avatar Aug 11 '22 09:08 ngocducdim

@ngocducdim

call setTargets after waitToChangeTarget

daybrush avatar Aug 12 '22 05:08 daybrush

I have call setTargets, but still can't work, my small part of the code: image image image

  • Try to select: image
  • The console output: image

ngocducdim avatar Aug 15 '22 10:08 ngocducdim

@ngocducdim

Okay. I'll check it again.

daybrush avatar Aug 15 '22 17:08 daybrush

@ngocducdim

0.38.2 was released. check it again.

daybrush avatar Aug 16 '22 01:08 daybrush

It works now, thank you for your fix!

ngocducdim avatar Aug 16 '22 07:08 ngocducdim