Skip to content
aq-ui
Back to HooksHook

Use File Drop

Open-code aq-ui React hook for Use File Drop.

Installation

pnpm dlx aq-ui@alpha add use-file-drop

API reference

Client module

Import the parts you need, then jump to an export for its contract.

View full source

Quick start

"use client"

import { useFileDrop } from "@/hooks/use-file-drop"

const result = useFileDrop()

FileDropBind

interfaceSource L21

Type contract for FileDropBind.

interface FileDropBind<T extends HTMLElement>

Members

NameType
isDraggingboolean
filesFile[]
rejectionsFileDropRejection[]
reset() => void
rootProps{ onDragEnter: React.DragEventHandler<T> onDragOver: React.DragEventHandler<T> onDragLeave: React.DragEventHandler<T> onDrop: React.DragEventHandler<T> }

FileDropRejection

interfaceSource L7

Type contract for FileDropRejection.

interface FileDropRejection

Members

NameType
fileFile
reason"type" | "size" | "multiple"

useFileDrop

functionSource L49

Open-code aq-ui React hook for Use File Drop.

function useFileDrop<T extends HTMLElement>({ accept = EMPTY_ACCEPT, multiple = true, maxSize = Number.POSITIVE_INFINITY, disabled = false, onDrop, onReject, }: UseFileDropOptions = {}): FileDropBind<T>
Returns
FileDropBind<T>

Parameters

NameTypeDefault
options?UseFileDropOptions{}
const result = useFileDrop()

UseFileDropOptions

interfaceSource L12

Type contract for UseFileDropOptions.

interface UseFileDropOptions

Members

NameTypeDefault
accept?string[]EMPTY_ACCEPT
multiple?booleantrue
maxSize?numberNumber.POSITIVE_INFINITY
disabled?booleanfalse
onDrop?(files: File[]) => void—
onReject?(rejections: FileDropRejection[]) => void—

Registry dependencies

use-stable-callback

Files

  • hooks/use-file-drop.ts

Source