gridland
Hooks

useFileDrop

Listen for file drops onto the canvas

The useFileDrop hook listens for file drops onto the canvas and provides drag-over state for visual feedback.

Import
import { useFileDrop } from "@gridland/web"

Usage

Basic
function FileDropZone() {
  const { isDragOver } = useFileDrop((file) => {
    console.log(`Dropped: ${file.name} (${file.size} bytes)`)
    console.log(file.content)
  })

  return (
    <box border borderColor={isDragOver ? "green" : "gray"}>
      <text>{isDragOver ? "Drop here!" : "Drag a file here"}</text>
    </box>
  )
}

Parameters

ParamTypeDescription
callback(file: DroppedFile) => voidCalled when a file is dropped

Returns

PropertyTypeDescription
isDragOverbooleantrue while a file is being dragged over the canvas

DroppedFile

PropertyTypeDescription
namestringFile name
contentstringFile content as a string
typestringMIME type
sizenumberFile size in bytes