fn

useFileDialog

v0.0.14testeddemo

Open a native file dialog programmatically and reactively track the selected files.

Examples

ts
const { files, open, onChange } = useFileDialog({ accept: 'image/*' });
onChange((selected) => console.log(selected));
open();
ts
// Override options for a single call
const { open } = useFileDialog();
open({ multiple: false, accept: '.pdf' });

Demo

Loading demo…

Signature

ts
export function useFileDialog(options: UseFileDialogOptions ={ ... }

Parameters

ParameterTypeDescription
options?UseFileDialogOptionsOptions

Returns

UseFileDialogReturnfiles, open, reset, onChange, and onCancel
PropertyTypeDescription
filesComputedRef<FileList | null>The currently selected files, or null when none are selected
open(localOptions?: Partial<UseFileDialogOptions>) => voidOpen the file dialog, optionally overriding options for this call only
reset() => voidClear the current selection
onChangeFileDialogEventHookOn<FileList | null>Register a callback fired when the selection changes
onCancelFileDialogEventHookOnRegister a callback fired when the dialog is dismissed without a selection