logo

X6

  • Tutorials
  • API
  • Examples
  • Q&A
  • Change Log
  • XFlow
  • Productsantv logo arrow
  • 2.x
  • start
    • Introduction
    • Quick Start
  • component
    • XFlowGraph Canvas
    • Background
    • Grid
    • Clipboard Copy and Paste
    • History Undo Redo
    • Minimap
    • Snapline Alignment Lines
    • Transform
    • Control Controller
  • Hook
    • useGraphInstance
    • useGraphStore
    • useGraphEvent
    • useDnd
    • useClipboard
    • useExport
    • useHistory
    • useKeyboard
  • Store

useDnd

Previous
useGraphEvent
Next
useClipboard

Resource

Ant Design
Galacea Effects
Umi-React Application Framework
Dumi-Component doc generator
ahooks-React Hooks Library

Community

Ant Financial Experience Tech
seeconfSEE Conf-Experience Tech Conference

Help

GitHub
StackOverflow

more productsMore Productions

Ant DesignAnt Design-Enterprise UI design language
yuqueYuque-Knowledge creation and Sharing tool
EggEgg-Enterprise-class Node development framework
kitchenKitchen-Sketch Tool set
GalaceanGalacean-Interactive solution
xtechLiven Experience technology
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

Quickly implement a hook for node dragging and dropping.

Basic Usage

const { startDrag } = useDnd();

API

const {
startDrag: (n, e) => void
} = useDnd(options: Options);

Return Value

ParameterDescriptionTypeDefault Value
startDragFunction to drag nodes(n: NodeOptions, e: React.MouseEvent<Element, MouseEvent>) => void-

NodeOptions, in addition to inheriting from Node type, has two additional properties.

For Node-related documentation, please refer to Node.

interface NodeOptions extends Node {
selected?: boolean; // Whether the node is selected
draggable?: boolean; // Whether the node is draggable
}

Parameters

ParameterDescriptionTypeDefault Value
optionsDrag configurationOptions-

When using useDnd for dragging, you can configure it.

The Options type is as follows:

ParameterDescriptionTypeDefault Value
scaledWhether the dragged node should be scaledbooleanfalse
dndContainerIf dndContainer is set, releasing the mouse on dndContainer will not place the node, commonly used in scenarios where the dnd container is above the canvasHTMLElement-
draggingContainerCustom dragging canvas containerHTMLElementdocument.body
validateNodeWhether the dragged node should be validated`(droppingNode: Node, options: ValidateNodeOptions) => booleanPromise`
node1
node2
node3