React DnD make dropTargets when hover on something while dragging item

夙愿已清 提交于 2019-12-01 12:25:48

问题


I'm trying to do something like below:

Scenario 1: User will drag and drop List 1 from left side to right side.

Scenario 2: Again, User will drag list 2 to right side, when that dragging item hover on list 1, have to show drop zones to drop that list 2 item here.

Finally, List 1 and List 2 both will be placed like left and right side.

With React Dnd, Is this achievable? and I tried this it works only while dragging. https://stackblitz.com/edit/react-pctpdh

I'm able to show a drop area while dragging, it shows every time, but I need to show that drop area only hover on some item.

Below is the sample work, I have to achieve:

Need to show placeholder to drop an item while hover other items to drop. (Need to Create dynamic drop targets while mouse hover some item)

I need a help on this to achieve this feature.Any idea on this really commendable.


回答1:


I saw the code snippet and i added some new code that replicates your desired behavior.

The idea is to create a separate component to handle drop actions, that can be reused when is needed. In this particular case, I choose to use the component inside your ListItem component to create two drop zones on both sides.

Here is the updated code: https://stackblitz.com/edit/react-pctpdh



来源:https://stackoverflow.com/questions/58555543/react-dnd-make-droptargets-when-hover-on-something-while-dragging-item

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!