shadcn-ahooks

useDrag

A pair of hooks to help you manage data transfer between drag and drop

Overview

A pair of hooks to help you manage data transfer between drag and drop

Documentation and Examples

Installation

Open in
pnpm dlx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useDrag.json
npx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useDrag.json
yarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useDrag.json
bun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useDrag.json

Basic Usage

Customize Image

API

useDrag

useDrag<T>(
  data: any,
  target: (() => Element) | Element | MutableRefObject<Element>,
  options?: DragOptions
);

Params

PropertyDescriptionTypeDefault
dataDrag dataany-
targetDOM element or ref() => Element | Element | MutableRefObject<Element>-
optionsMore configDragOptions-

DragOptions

PropertyDescriptionTypeDefault
onDragStartOn drag start callback(e: React.DragEvent) => void-
onDragEndOn drag end callback(e: React.DragEvent) => void-
dragImageCustomize image that follow the mouse pointer during draggingDragImageOptions-

DragImageOptions

参数说明类型默认值
imageAn image Element element to use for the drag feedback image. The image will typically be an <img> element but it can also be a <canvas> or any other visible elementstring | Element-
offsetXthe horizontal offset within the imagenumber0
offsetYthe vertical offset within the imagenumber0

On this page