shadcn-ahooks

useDrop

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/useDrop.json
npx shadcn@latest add https://shadcn-ahooks.vercel.app/r/useDrop.json
yarn shadcn@latest add https://shadcn-ahooks.vercel.app/r/useDrop.json
bun shadcn@latest add https://shadcn-ahooks.vercel.app/r/useDrop.json

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

useDrop can be used alone to accept file, text or uri dropping.

useDrag should be used along with useDrop.

Paste into the drop area will also be treated as content drop.

Examples

Basic Usage

Customize Image

API

useDrop

useDrop<T>(
  target: (() => Element) | Element | MutableRefObject<Element>,
  options?: DropOptions
);

Params

PropertyDescriptionTypeDefault
targetDOM element or ref() => Element | Element | MutableRefObject<Element>-
optionsMore configDropOptions-

DropOptions

PropertyDescriptionTypeDefault
onTextThe callback when text is dropped or pasted(text: string, e: React.DragEvent) => void-
onFilesThe callback when file is dropped or pasted(files: File[], e: React.DragEvent) => void-
onUriThe callback when uri is dropped or pasted(text: string, e: React.DragEvent) => void-
onDomThe callback when DOM is dropped or pasted(content: any, e: React.DragEvent) => void-
onDropThe callback when any is dropped(e: React.DragEvent) => void-
onPasteThe callback when any is pasted(e: React.DragEvent) => void-
onDragEnterOn drag enter callback(e: React.DragEvent) => void-
onDragOverOn drag over callback(e: React.DragEvent) => void-
onDragLeaveOn drag leave callback(e: React.DragEvent) => void-

On this page