MCPcopy Create free account
hub / github.com/dailydotdev/apps / useFileInput

Function useFileInput

packages/shared/src/hooks/utils/useFileInput.ts:11–38  ·  view source on GitHub ↗
({
  limitMb,
  acceptedTypes,
  onChange,
}: UseFileInputProps)

Source from the content-addressed store, hash-verified

9}
10
11export const useFileInput = ({
12 limitMb,
13 acceptedTypes,
14 onChange,
15}: UseFileInputProps) => {
16 const { displayToast, dismissToast } = useToastNotification();
17 const onFileChange = async (file?: File | null) => {
18 if (!file) {
19 return;
20 }
21
22 if (file.size > limitMb * MEGABYTE) {
23 displayToast(`Maximum image size is ${limitMb} MB`);
24 return;
25 }
26
27 if (acceptedTypes && !acceptedTypes.includes(file.type)) {
28 displayToast(`File type is not allowed`);
29 return;
30 }
31
32 const base64 = await blobToBase64(file);
33 dismissToast();
34 onChange(base64, file);
35 };
36
37 return { onFileChange };
38};

Callers 6

UploadButtonFunction · 0.90
SquadDetailsFunction · 0.90
ImageInputFunction · 0.90
DragDropComponentFunction · 0.90
TextForm.tsxFile · 0.90
useControlledImageUploadFunction · 0.90

Calls 1

useToastNotificationFunction · 0.90

Tested by

no test coverage detected