Frontend Blocks typescript Intermediate

Drag and Drop with dnd-kit

Sortable list using dnd-kit — accessible drag-and-drop with keyboard support.

typescript
import { DndContext, closestCenter } from "@dnd-kit/core";
import { SortableContext, useSortable, arrayMove } from "@dnd-kit/sortable";
import { CSS } from "@dnd-kit/utilities";

function SortableItem({ id }: { id: string }) {
  const { attributes, listeners, setNodeRef, transform, transition } = useSortable({ id });
  return (
    <div ref={setNodeRef}
         style={{ transform: CSS.Transform.toString(transform), transition }}
         {...attributes} {...listeners}
         className="p-4 bg-slate-800 rounded-xl cursor-grab">
      {id}
    </div>
  );
}

Prerequisites

  • @dnd-kit/core >= 6
  • React >= 17

Pro Tips

  • → Use DragOverlay for smooth drag preview.

Was this module useful?

Share your experience — it helps the team improve.

Leave Feedback

Commercial Licensing

Acquire a production access token or template license for enterprise deployment.

Module Info

Language
typescript
Level
Intermediate
Read time
5 min
Published
Oct 2025
License
Commercial License

Newsletter

New modules every week, directly to your inbox.