Replies: 1 comment
-
I found a better example under Presets/Sortable/Multiple containers. I'm still wrapping my head around the MultipleContainers component, but it looks like in the onDragOver and onDragEnd handlers, the way it finds the original container's Id is by performing a linear search for the draggable's Id in each of the containers. Given that this is one of the official examples, I'll take it that this how we're meant to find the original container's Id, but it seems like an inefficient of doing so, especially when there's a large number of items. At worst, you're sweeping through your entire list both during on drag over and on drag end. But I still need to understand the full example, and maybe there's a reason why it's done this way. |
Beta Was this translation helpful? Give feedback.
-
I feel like I'm missing a basic part of dnd-kit's API. When moving a draggable item between droppables, how do I know which droppable that item came from (i.e. the item's original parent droppable)?
More context:
I have a collection of droppables, each which can contain more than one draggable. The contents of each droppable are driven by the app's internal state via useState in a parent component.
When the user moves a draggable from one droppable to another, I'd like to update the app's state to update the contents of both droppables. I need to remove that draggable from the origin droppable to the target one. The
onDragEnd
event handler forDndContext
gives me a reference to the target droppable via theover
property, but I can't find a way to get a reference for the droppable where the draggable came from.I think I'm misunderstanding something because the way I see it, you'd need to know this information to support moving draggable between different droppables. The example for multiple droppables doesn't deal with this because it's only keeping track of a single draggable.
I can think of workarounds like maybe using
data
inside of a draggable to store information about it's current droppable parent, but that seems hacky. What are others using to get a reference to the origin droppable? Am I missing something?Beta Was this translation helpful? Give feedback.
All reactions