tajo / react-movable

🔀 Drag and drop for your React lists and tables. Accessible. Tiny.
https://react-movable.pages.dev
MIT License
1.55k stars 51 forks source link

Preserving custom component item state while dragging #70

Closed Cheppa closed 3 years ago

Cheppa commented 3 years ago

I am unsure if it's possible to accomplish what I'm trying to do in this codesandbox:

https://codesandbox.io/s/heuristic-breeze-osx1e

All items have their own toggle button that hides content inside the item. The toggled state is handled inside the Item component with useState hook.

When the content is hidden and the item is dragged, the content becomes visible in the dragged element. In the image, the "Toggleable stuff" should be hidden on the dragged item.

image

Is this possible? How can I preserve the toggled state in the dragged component without moving the state outside the items.

Thanks in advance for any help!

tajo commented 3 years ago

How can I preserve the toggled state in the dragged component without moving the state outside the items

You can't, the state needs to be outside of the dragged item. The dragged item is being re-mounted, that's why the internal state is lost.