Providing additional props in DragEndEvent #202
-
As far as I know, there are only id properties one a drag end event. This becomes a bit limiting for more complex drag-and-drop interfaces, especially with tree like structures. Since all the logic becomes centralized in the It would be nice to be able to add additional properties besides the id. Or alternatively, provide drop logic in the droppable component itself. In that world, components can decide how to update the data structure instead of at the top level. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hey @airtable-JayRansijn, this is planned, just haven't had a chance to make time to work on this yet. Refer to this discussion #139 (comment) |
Beta Was this translation helpful? Give feedback.
-
As of version Example usage: import {DndContext, useDraggable, useDroppable} from '@dnd-kit/core';
function Draggable() {
const {attributes, listeners, setNodeRef, transform} = useDraggable({
id: 'draggable',
data: {
type: 'type1',
},
});
/* ... */
}
function Droppable() {
const {setNodeRef} = useDroppable({
id: 'droppable',
data: {
accepts: ['type1', 'type2'],
},
});
/* ... */
}
function App() {
return (
<DndContext
onDragEnd={({active, over}) => {
if (over?.data.current.accepts.includes(active.data.current.type)) {
// do stuff
}
}}
/>
);
} Refer to https://docs.dndkit.com/api-documentation/droppable/usedroppable#data and https://docs.dndkit.com/api-documentation/draggable/usedraggable#data for more details. |
Beta Was this translation helpful? Give feedback.
As of version
^3.0.0
of@dnd-kit/core
, thedata
argument foruseDraggable
anduseDroppable
is now exposed in event handlers and on theactive
andover
objects.Example usage: