0PricingLogin
React Academy · Lesson

DndContext, useDraggable, and useDroppable

Wire up the DndContext provider and create draggable and droppable elements with their respective hooks.

Wrapping Your Feature with DndContext

Every drag-and-drop feature in dnd-kit must be wrapped in a DndContext component. DndContext is the coordination hub — it tracks active drags, communicates between draggables and droppables, and fires event callbacks. You typically place it at the level of the component that manages drag state.

useDraggable Hook Anatomy

The useDraggable({ id }) hook makes a component draggable. It returns four key values: attributes (ARIA props to spread on the element), listeners (event handlers for drag initiation), setNodeRef (attaches the draggable ref), and transform (the current translation as {x, y, scaleX, scaleY}).

All lessons in this course

  1. dnd-kit Architecture and Accessibility-First Design
  2. DndContext, useDraggable, and useDroppable
  3. SortableContext for Reorderable Lists
  4. Custom Drag Overlays and Multi-Container DnD
← Back to React Academy