简体   繁体   中英

React Drag and Drop - react-dnd - make component draggable and droppable at the same time (apply both roles - drag and drop)

I created a simplified version of my app.

It is here: https://codesandbox.io/s/quirky-glade-x4h51

当前的应用布局

Current version has bookmarks (top row) and places for them. When used drags bookmark from bookmarks row and drops it to place, everything works fine. But what if user drag one of the places and want to move it somewhere?

I wrapped PlaceForChart component both to DropTarget() and DragSource() and exported wrapped component. But it is not working properly. If a remove any of wrappers, it will work.

Currently when user tries to drag any of PlaceForChart components (orange), the component changes color (as expected), but doesn't move.

How to make it work?

I changed key={Math.random()} in PlaceForChart.tsx and it started working. There are some other issues, but they are not related to dnd behavior. This was the main one.

Working version: https://codesandbox.io/s/billowing-wave-tjugx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM