Skip to Content
ohooks

useFileDialog

Opens the native file selection dialog programmatically without rendering a visible <input type="file"> element.

Loading preview...

The useFileDialog hook creates and manages an off-DOM file input so you can trigger the native file picker from any button or action and read the selected FileList reactively.

Installation

pnpm dlx shadcn@latest add https://ohooks.vercel.app/r/useFileDialog.json

Usage

Examples

Selecting and Clearing Files

Call open() from any click handler to launch the native file dialog and reset() to clear the selection.

Overriding Options Per Invocation

Pass per-call options directly to open() to reuse the same hook instance for different file types.

API Reference

UseFileDialogOptions

Configuration options for the file picker.

Property
Specification
multiple?
uniondefault:true
Allow selecting multiple files
accept?
stringdefault:'*'
Accepted file types or extensions
capture?
string
Media capture source ('user' or 'environment') for mobile devices
directory?
uniondefault:false
Allow selecting directories via webkitdirectory
reset?
uniondefault:false
Reset previously selected files when opening the dialog
onChange?
function
Callback fired when files are selected
onCancel?
function
Callback fired when the file dialog is canceled without selection

UseFileDialogReturn

Selected files and control functions returned by the hook.

Property
Specification
files
union
Currently selected FileList, or null
open
function
Opens the native file picker dialog with optional per-call overrides
reset
function
Clears the selected files state and resets the underlying file input