Configs2026年5月28日·1 分钟阅读

React DnD — Drag and Drop for React Applications

A set of React utilities for building complex drag-and-drop interfaces while keeping components decoupled.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
React DnD Overview
直接安装命令
npx -y tokrepo@latest install 14dd9b81-5a2a-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

React DnD is a drag-and-drop library for React built on a flexible backend architecture. Rather than wrapping the DOM drag-and-drop API directly, it exposes a set of hooks and higher-order components that let you describe drag sources and drop targets declaratively.

What React DnD Does

  • Provides useDrag and useDrop hooks for declarative drag-and-drop logic
  • Supports swappable backends (HTML5, Touch, custom)
  • Enables complex interactions like sortable lists, kanban boards, and file drops
  • Handles drag previews, custom layers, and snapping behavior
  • Works with React's concurrent rendering and strict mode

Architecture Overview

React DnD uses a monitor-based architecture inspired by Flux. A central DnD manager tracks drag state, while backends translate platform events into internal actions. Components subscribe to state changes through hooks, and the library reconciles updates efficiently without re-rendering the entire tree.

Self-Hosting & Configuration

  • Install the core package and at least one backend (HTML5 or Touch)
  • Wrap your app in <DndProvider backend={...}> at the root level
  • Configure drag preview images using the preview connector
  • Use useDragLayer for custom floating drag layers
  • Combine with react-dnd-multi-backend for simultaneous mouse and touch support

Key Features

  • Hook-based API that integrates cleanly with modern React patterns
  • Backend-agnostic design allows testing without a real DOM
  • Built-in support for nested drop targets with priority resolution
  • Drag preview customization via custom render layers
  • TypeScript support with full generic type parameters

Comparison with Similar Tools

  • dnd-kit — Newer alternative with simpler API; React DnD is more mature with broader community adoption
  • react-beautiful-dnd — Opinionated and specialized for vertical/horizontal list reordering; React DnD is more general
  • SortableJS — Framework-agnostic but less idiomatic in React; React DnD is designed for React
  • Pragmatic drag and drop — Atlassian's lightweight approach; React DnD offers more built-in abstractions

FAQ

Q: Does React DnD support touch devices? A: Yes. Use the react-dnd-touch-backend package alongside or instead of the HTML5 backend.

Q: Can I use it with Next.js or SSR? A: Yes, but the HTML5 backend requires a browser environment. Use dynamic imports or conditional rendering for SSR.

Q: How does it compare to the native HTML5 drag-and-drop API? A: React DnD wraps the native API via backends and adds state management, type matching, and preview handling that the raw API lacks.

Q: Is it still actively maintained? A: The project receives community contributions and remains widely used in production across many large codebases.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产