Skip to main content

Overview

This guide walks you through creating a simple drag and drop interface using dnd-kit. You’ll learn the fundamental concepts of making elements draggable and droppable, and how to manage state when items are moved between containers.

What You’ll Build

A basic drag and drop interface where you can:
  • Drag an item from its initial position
  • Drop it into a designated drop zone
  • See visual feedback when hovering over the drop zone

Installation

First, install the required packages:

Implementation

Complete Example

Here’s the full working code:

Styling

Add basic CSS to make the interface visually clear:

Key Takeaways

  • DragDropProvider wraps your app and provides drag and drop context
  • useDraggable makes elements draggable by providing a ref
  • useDroppable creates drop zones with visual feedback via isDropTarget
  • onDragEnd event handler updates state when drag operations complete
  • Check event.canceled to handle cancelled drag operations
  • Use event.operation.target?.id to identify where the item was dropped

Next Steps