最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

reactjs - How can I change the default "Upload file" button to a custom component in upload care? - Stack Over

matteradmin8PV0评论

How can I change the default "Upload file" button to a custom component in upload care?

import { FileUploaderRegular } from '@uploadcare/react-uploader/next'

<FileUploaderRegular
  sourceList="local, url, camera, gdrive"
  pubkey={process.env.NEXT_PUBLIC_UPLOADCARE_PUBLIC_KEY!}
  multiple={false}
/>

Currently it renders the following as in the image:

I want to have something like a custom component where if it was clicked, it will open the modal.

For example this is my use case:

I wanted to have my custom component to have the users to click on, but I found not way to hide the default upload button and show my own trigger element.

How can I change the default "Upload file" button to a custom component in upload care?

import { FileUploaderRegular } from '@uploadcare/react-uploader/next'

<FileUploaderRegular
  sourceList="local, url, camera, gdrive"
  pubkey={process.env.NEXT_PUBLIC_UPLOADCARE_PUBLIC_KEY!}
  multiple={false}
/>

Currently it renders the following as in the image:

I want to have something like a custom component where if it was clicked, it will open the modal.

For example this is my use case:

I wanted to have my custom component to have the users to click on, but I found not way to hide the default upload button and show my own trigger element.

Share Improve this question edited Nov 17, 2024 at 8:39 rozsazoltan 11.6k6 gold badges21 silver badges61 bronze badges asked Nov 16, 2024 at 22:06 NormalNormal 3,8277 gold badges37 silver badges84 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 0

The default uploader button can be hidden with CSS

lr-simple-btn {
  display: none;
}

After that, the uploader dialog can be triggered via the JS API by calling the initFlow() method. For example,

import { FileUploaderRegular } from "@uploadcare/react-uploader";
import "@uploadcare/react-uploader/core.css";
import { useRef } from "react";

function Uploader() {
  const uploaderRef = useRef(null);

  return (
    <div>
      <FileUploaderRegular apiRef={uploaderRef} pubkey="YOUR_PUBLIC_KEY" />
      <button
        onClick={() => {
          uploaderRef.current.initFlow();
        }}
      >
        Upload file
      </button>
    </div>
  );
}

export default Uploader;

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far