pingdotgg / uploadthing

File uploads for modern web devs
https://uploadthing.com
MIT License
3.97k stars 290 forks source link

feat: `useUploadThingInputProps` #729

Open t3dotgg opened 5 months ago

t3dotgg commented 5 months ago

Describe the feature you'd like to request

Making custom upload buttons is too hard

Describe the solution you'd like to see

// inferred input off useUploadThing
type Input = Parameters<typeof useUploadThing>;

const useUploadThingInputProps = (...args: Input) => {
  const $ut = useUploadThing(...args);

  const handleChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
    if (!e.target.files) return;

    const selectedFiles = Array.from(e.target.files);
    const result = await $ut.startUpload(selectedFiles);
  };

  return {
    inputProps: {
      handleChange,
      multiple: ($ut.permittedFileInfo?.config?.image?.maxFileCount ?? 1) > 1,
      accept: generateMimeTypes(fileTypes ?? [])?.join(", "),
    },
    isUploading: $ut.isUploading,
  };
};

Can I have this pls <3

Additional information

No response

๐Ÿ‘จโ€๐Ÿ‘งโ€๐Ÿ‘ฆ Contributing