Skip to content

feat: useUploadThingInputProps #729

@t3dotgg

Description

@t3dotgg

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

  • 🙋‍♂️ Yes, I'd be down to file a PR implementing this feature!

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleNo activity in the past 10 daysstatus: in progresswork is currently underway to address this issue✨ enhancementsuggestion or feature request to improve uploadthing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions