mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-20 00:51:17 -08:00
16 lines
419 B
TypeScript
16 lines
419 B
TypeScript
import { useCallback } from 'react';
|
|
import { selectFile } from '$utils/dom';
|
|
|
|
export const useFilePicker = <M extends boolean | undefined = undefined>(
|
|
onSelect: (file: M extends true ? File[] : File) => void,
|
|
multiple?: M
|
|
) =>
|
|
useCallback(
|
|
async (accept: string) => {
|
|
const file = await selectFile(accept, multiple);
|
|
if (!file) return;
|
|
onSelect(file);
|
|
},
|
|
[multiple, onSelect]
|
|
);
|